简体   繁体   English

无法在virtualenv中导入软件包

[英]Can't import packages in virtualenv

I've seen a bunch of similar questions but somehow can't get over it. 我见过很多类似的问题,但总不能解决。

I am on Ubuntu. 我在Ubuntu上。 It uses python2.7 by default but I needed python3. 默认情况下使用python2.7,但我需要python3。 I figured out the way best was to use virtualenv. 我想出了最好的方法是使用virtualenv。 So I did. 所以我做了。 I created a virtualenv using python 3 and installed some packages. 我使用python 3创建了virtualenv并安装了一些软件包。

When I run (with env turned on): 当我运行(打开环境)时:

import sys
print(sys.executable)

I get: 我得到:

/usr/bin/python3

which does not seem correct. 这似乎不正确。 This is not the virtualenv python path. 这不是virtualenv python路径。 As a result I can't import any packages that I had installed inside of the virtualenv. 结果,我无法导入我在virtualenv内部安装的任何软件包。 Ideas? 想法?

You might want to use a virtualenv version especially for python3: On Ubuntu 14.04 for example use pyvenv-3.4 . 您可能要使用virtualenv版本,尤其是针对python3:例如,在Ubuntu 14.04上,使用pyvenv-3.4

You code example runs fine with pyvenv-3.4: 您的代码示例在pyvenv-3.4上运行良好:

(python-venv) user:~/tmp/test/python-venv$ python test.py 
/home/user/tmp/test/python-venv/bin/python

additionally, python --version and which python both return the expected results: 另外, python --versionwhich python都返回预期结果:

(python-venv) user:~/tmp/test/python-venv$ which python
/home/user/tmp/test/python-venv/bin/python
(python-venv) user:~/tmp/test/python-venv$ python --version
Python 3.4.0

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

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