简体   繁体   中英

Package not found on virtualenv - No module named “mypack”

Hi !

I've tried to use a package I've created (named mypackage ) on my main program (named collector ). mypackage is defined with the setup.py below:

name = "mypackage"
[...]
packages = find_packages(),
include_package_data = True,
exclude_package_data = { '': ['README.md'] }
[...]
entry_points = {
    'console_scripts': [
        'my-package=mypack.mypack:main'
    ]
},

I want to use a little program present this package, which will normally be called as below on collector :

from mypack.common.prog import mylittleprogram

I've tried to install mypackage on a virtualenv, and then (re)installed my main program. Then I executed it, and there is the error I have:

Traceback (most recent call last):
from project.common.collector import collectArt
File "/root/project/lib/python3.5/site-packages/collector-0.1-py3.5.egg/project/common/collector.py", line 7, in <module>
ImportError: No module named 'mypack'

Also, when the virtualenv is activated, I've just tried to launch the entry-point named my-package :

Traceback (most recent call last):
File "/root/project/bin/my-package", line 11, in <module>
load_entry_point('mypackage==0.1.1', 'console_scripts', 'my-package')()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 560, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2648, in load_entry_point
return ep.load()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2302, in load
return self.resolve()
File "/root/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2308, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named 'mypack'

Note 1: I precise that I have the __init__.py on each folder of my package.

Note 2: the virtualenv folders are on the same folder as my main program.

How do I use mylittleprogram present on mypackage on my collector main program with virtualenv ? Did I made something wrong ?

Thank you :)

There is the issue, I had to install my package via the following command:

python setup.py develop

And then the package is recognized. This command has to be executed when the virtualenv is activated, and be executed on the directory of the package.

Hope this will help someone in the future !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM