[英]Import error with virtualenv
I have a problem with virtualenv. 我有virtualenv的问题。 I use it regulary, I use it on my development machine and on several servers. 我经常使用它,我在我的开发机器和几台服务器上使用它。 But on this last server I tried to use i got a problem. 但在最后一台服务器上我尝试使用我遇到了问题。
I created a virtualenv with the --no-site-packages argument, and then I installed some python modules inside the virtualenv. 我使用--no-site-packages参数创建了一个virtualenv,然后我在virtualenv中安装了一些python模块。 I can confirm that the modules is located inside the virtualenvs site-packages and everything seems to be fine. 我可以确认模块位于virtualenvs站点包内,一切似乎都没问题。
But when i try to do: source virtualenv/bin/activate
and then import one of the module python import modulename
i get an import error that says that the module doesnt exist. 但是当我尝试这样做: source virtualenv/bin/activate
然后导入一个模块python import modulename
我得到一个导入错误,表明该模块不存在。 How is it that this is happending? 这是怎么回事? It seems like it never activates even thoug that it says it do. 它似乎永远不会激活甚至它所说的那样。
Anybody have a clue on how to fix this? 有谁知道如何解决这个问题?
Is there a bash alias active on this machine for "python", by any chance? 在这台机器上是否有一个bash别名为“python”活动,任何机会? That will take priority over the PATH-modifications made by activate, and could cause the wrong python binary to be used. 这将优先于activate激活的PATH修改,并可能导致使用错误的python二进制文件。
Try running virtualenv/bin/python directly (no need to activate) and see if you can import your module. 尝试直接运行virtualenv / bin / python(无需激活),看看是否可以导入模块。
If this fixes it, you just need to get rid of your python bash alias. 如果这个修复它,你只需要摆脱你的python bash别名。
After activating the virtual env, try: 激活虚拟环境后,尝试:
$ python
>>> import sys
>>> sys.executable
...
... and see if you are running the expected executable. ...并查看您是否正在运行预期的可执行文件。
Also check: 还检查:
>>> sys.path
[...]
IIRC, the activate script just puts your virtual env first on your path, so when you type "python" it finds the one in your virtual env first. IIRC,激活脚本只是将您的虚拟环境放在您的路径上,因此当您键入“python”时,它首先在您的虚拟环境中找到它。 If the activate script fails, you can always edit your path manually. 如果激活脚本失败,您始终可以手动编辑路径。 Also - go here and search for "activate": http://pylonsbook.com/en/1.1/installing-pylons.html#setting-up-a-virtual-python-environment . 另外 - 到这里搜索“激活”: http : //pylonsbook.com/en/1.1/installing-pylons.html#setting-up-a-virtual-python-environment 。 This will tell you why the activate command can fail. 这将告诉您为什么activate命令可能失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.