使用 virtualenv 导入错误 [英] Import error with virtualenv

查看:25
本文介绍了使用 virtualenv 导入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 virtualenv 时遇到问题.我经常使用它,我在我的开发机器和几台服务器上使用它.但是在我尝试使用的最后一个服务器上,我遇到了问题.

I have a problem with 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.

我使用 --no-site-packages 参数创建了一个 virtualenv,然后我在 virtualenv 中安装了一些 python 模块.我可以确认这些模块位于 virtualenvs 站点包内,并且一切似乎都很好.

I created a virtualenv with the --no-site-packages argument, and then I installed some python modules inside the virtualenv. I can confirm that the modules is located inside the virtualenvs site-packages and everything seems to be fine.

但是当我尝试执行以下操作时:source virtualenv/bin/activate 然后导入一个模块 python import modulename 我收到一个导入错误,指出该模块不存在.这是怎么回事?即使它说它会激活,它似乎也永远不会激活.

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. 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?

推荐答案

在这台机器上是否有活动的 bash 别名python"?这将优先于激活所做的 PATH 修改,并可能导致使用错误的 Python 二进制文件.

Is there a bash alias active on this machine for "python", by any chance? That will take priority over the PATH-modifications made by activate, and could cause the wrong python binary to be used.

尝试直接运行 virtualenv/bin/python(无需激活),看看是否可以导入您的模块.

Try running virtualenv/bin/python directly (no need to activate) and see if you can import your module.

如果这解决了它,你只需要去掉你的 python bash 别名.

If this fixes it, you just need to get rid of your python bash alias.

这篇关于使用 virtualenv 导入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆