Python - 包在virtualenv中不起作用

时间:2017-02-11 18:54:35

标签: python virtualenv packages

我正在尝试创建一个包,并且我正在按照教程here进行操作。使用我的Mac上安装的本机Python时,代码工作正常,但是当我激活virtualenv时,它不起作用。你能告诉我为什么以及如何使这项工作?谢谢!

# python -V
Python 2.7.10
# source env/bin/activate
(env) # python -V
Python 3.6.0
(env) # python test.py
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    from Animals import Mammals
  File "/private/tmp/test/Animals/__init__.py", line 1, in <module>
    from Mammals import Mammals
ModuleNotFoundError: No module named 'Mammals'
(env) # deactivate
# python -V
Python 2.7.10
# python test.py
Printing members of the Mammals class
    Tiger
    Elephant
    Wild Cat
Printing members of the Birds class
    Sparrow
    Robin
    Duck
# ls -lrtah
total 8
-rw-r--r--  1 btm   wheel   324B Feb 12 02:29 test.py
drwxr-xr-x  5 btm   wheel   170B Feb 12 02:32 .
drwxr-xr-x  7 btm   wheel   238B Feb 12 02:32 env
drwxr-xr-x  9 btm   wheel   306B Feb 12 02:38 Animals
drwxrwxrwt  9 root  wheel   306B Feb 12 02:44 ..
# tree Animals
Animals
├── Birds.py
├── Birds.pyc
├── Mammals.py
├── Mammals.pyc
├── __init__.py
├── __init__.pyc
└── __pycache__
    └── __init__.cpython-36.pyc

# cat Animals/__init__.py
from Mammals import Mammals
from Birds import Birds
# virtualenv --version
15.0.3

0 个答案:

没有答案