473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

zipimport

Hi,

I have a zip file structured like this:

mymodule.zip\
module1.py
submodule\
submodule1.py

I tried to load submodule.submodule1 using this pice of code:

import zipimport

z = zipimport.zipimporter("mymodule.zip")
z.load_module("submodule.submodule1")

but it does not work (load_module raises an exception)

why?

tnx, bye
Jul 19 '05 #1
1 2291

"Gabriele *Darkbard* Farina" <da******@extending-php.net> wrote in message
news:fV***********************@news4.tin.it...
Hi,

I have a zip file structured like this:

mymodule.zip\
module1.py
submodule\
submodule1.py

I tried to load submodule.submodule1 using this pice of code:

import zipimport

z = zipimport.zipimporter("mymodule.zip")
z.load_module("submodule.submodule1")

but it does not work (load_module raises an exception)

why?


try z.load_module("submodule/submodule1") instead.

Or in otherwords replace the dot with a slash, now quoting from the docs
"'fullname' must be the fully qualified (dotted) module name.". The dotted
part of that doesn't seem to be correct, at least with the version of python
(2.3.4) I'm running.

Anyway personally I find:

import sys
sys.path.insert(0, 'mymodule.zip')
import submodule.submodule1

a much cleaner way of thinking about this.

--
Jonathan
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dan Bishop | last post by:
I installed Python on the HP 3000 at work today. The interpreter itself appears to be working fine, but "import math", "import datetime", etc. fail with "ImportError: No module named ". ...
43
by: Dan Perl | last post by:
Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file? Maybe a python specific file type, let's call it a...
1
by: Bob Swerdlow | last post by:
We have some users of our application getting error messages like: IOError: zipimport: can not open file /Volumes/MyApp/MyApp.app/Contents/Resources/Modules.zip This only happens on our Mac...
2
by: vivainio | last post by:
I may be on particularly potent crack, but I was wondering whether it would make sense to distribute python code in DLLs so that the memory occupied by the bytecode would be consumed only once even...
2
by: jiang.haiyun | last post by:
Hi, I am having some serious problems with PyQT4, when i run pyqt script, I always get 'Segmentation fault'. the script is simple: ====================== %less qttest.py from PyQt4 import...
1
by: shabda raaj | last post by:
I have a VPS server with fedora 7. I wanted to install easy_install on this server, but I got an error saying unable to open /usr/lib/ python2.5/config/Makefile (No such file or directory). So I...
4
by: Markus Dahlbokum | last post by:
Hello, I'm trying to link python statically with qt and pyqt. I've tried this in several ways but never succeeded. At the moment the final make runs without errors but I get import errors when...
4
by: vedrandekovic | last post by:
Hello, Does anybody have any idea how can I embed my modules to libary.zip and use it from my application.For example if user write this code in my TextEntry ( or something like that, textentry...
1
by: jwahlmann | last post by:
I'm experiencing some strange behavior when starting up python on a Debian-based PowerPC platform. Normally, I operate from this platform with a root file system on an IDE flash drive (/dev/hda1)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.