简体   繁体   English

在virtualenv上找不到软件包-没有名为“ mypack”的模块

[英]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 ). 我尝试使用在主程序(名为collector )上创建的程序包(名为mypackage )。 mypackage is defined with the setup.py below: mypackage是通过以下setup.py定义的:

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 : 我想使用一个小程序来展示这个包,通常在collector上调用如下:

from mypack.common.prog import mylittleprogram

I've tried to install mypackage on a virtualenv, and then (re)installed my main program. 我尝试将mypackage安装在virtualenv上,然后(重新)安装我的主程序。 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 : 另外,在激活virtualenv时,我只是尝试启动名为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. 注1:我精确地指出,我的软件包的每个文件夹上都有__init__.py

Note 2: the virtualenv folders are on the same folder as my main program. 注意2: virtualenv文件夹与我的主程序位于同一文件夹中。

How do I use mylittleprogram present on mypackage on my collector main program with virtualenv ? 如何通过virtualenvcollector主程序上的mypackage上使用mylittleprogram 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. 激活virtualenv时必须执行此命令,并在软件包目录上执行。

Hope this will help someone in the future ! 希望这对以后的人有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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