如何重置 virtualenv 和 pip?
我在 Ubuntu 10.04 服务器上安装了 virtualenv。
现在,当我执行 pip freeze 时,它会显示以下软件包:
Django==1.2.4
distribute==0.6.10
python-apt==0.7.94.2ubuntu6.2
virtualenv==1.5.1
wsgiref==0.1.2
当我执行“pip uninstall Django”时,它会说:
pip uninstall Django
Uninstalling Django:
Proceed (y/n)? y
Successfully uninstalled Django
理想情况下,这应该卸载 Django,但事实并非如此。当我执行“pip freeze”时,我仍然可以看到相同的包。
现在请耐心等待,另一件奇怪的事情是,当我创建一个 virtualenv 然后在其中执行“pip freeze”时,我只看到一个包,那就是“wsgiref”,这很奇怪,因为理想情况下它应该是空白的。
另外,尽管使用 --no-site-packages 创建这个 virtualenv,我仍然可以使用“django-admin.py startproject”创建一个新的 django 项目。
当我在这个 virtualenv 中启动 python 解释器并执行“import django”时,它给出错误“No module named django”。
另外,当我尝试在 virtualenv 内安装“pip install Django”时,它会要求 sudo 权限,但理想情况下这不会发生。
我该如何解决这个烂摊子。有什么方法可以重置所有 pep 和 virtualenv 吗?
I installed virtualenv on my Ubuntu 10.04 server.
Now when I do pip freeze it shows me the following packages:
Django==1.2.4
distribute==0.6.10
python-apt==0.7.94.2ubuntu6.2
virtualenv==1.5.1
wsgiref==0.1.2
When I do "pip uninstall Django" it says:
pip uninstall Django
Uninstalling Django:
Proceed (y/n)? y
Successfully uninstalled Django
Ideally this should uninstall Django but it doesn't. I can still see the same packages when I do "pip freeze".
Now bear with me, the other weird thing is that when I create a virtualenv and then do "pip freeze" inside it, I see only one package and that is "wsgiref" which is weird because it should ideally be blank.
Also, in spite of creating this virtualenv with --no-site-packages I can still create a new django project with "django-admin.py startproject".
When I start python interpreter inside this virtualenv and do "import django" it gives me the error "No module named django".
Also when I try to install "pip install Django" inside the virtualenv it asks for sudo permissions which shouldn't happen ideally.
How do I sort out this mess. Any way to just reset everything pep and virtualenv?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,venv 的唯一目的是管理依赖关系。
您应该可以安全地
停用
venv,将其删除,然后使用virtualenv venv 创建一个新的;源 venv/bin/activate
。这会给你一个新的开始。
As far as I can tell, the only purpose of a venv is to manage dependencies.
You should be safe to just
deactivate
the venv, delete it, and create a new one usingvirtualenv venv; source venv/bin/activate
.This will give you a fresh start.
这个问题很老了,但它被撞到了首页,所以很难辨别你正在使用哪个版本的 pip 和 virtualenv。
尽管如此,我们还是可以采取一些措施来纠正这个问题。
$PYTHONPATH
。确保它是空的;否则运行unset PYTHONPATH
。virtualenv --no-site-packages myenv
在myenv
创建一个新的 virtualenv。myenv
并再次检查您的$PYTHONPATH
。它应该只有myenv
。pip
,例如myenv/bin/pip freeze
。pip
在您的 virtualenv 中不可用,您可能需要手动安装它。相关: virtualenv --no-site-packages 和 pip仍在查找全局包吗?
最后,使用
myenv/bin/python
启动 python shell,然后运行:If
pip
can findwsgiref
>,那么wsgiref
必须位于sys.path
中的路径之一。使用那个线索!This question is old, but it got bumped to the front page, so it's hard to discern which versions of pip and virtualenv you are using.
There are a few things we can do to straighten this, nonetheless.
$PYTHONPATH
. Make sure it's empty; else rununset PYTHONPATH
.myenv
usingvirtualenv --no-site-packages myenv
.myenv
and check your$PYTHONPATH
again. It should only havemyenv
.pip
with an absolute path, like somyenv/bin/pip freeze
.pip
is not available inside your virtualenv, you may have to install it manually.Related: virtualenv --no-site-packages and pip still finding global packages?
Finally, start a python shell using
myenv/bin/python
, then run:If
pip
can findwsgiref
, thenwsgiref
must be in one of the paths insys.path
. Use that clue!您只需删除 .venv 文件即可删除所有依赖项,然后运行 python3 -m venv .venv 以获得全新的虚拟环境。
You can just delete your .venv file to remove all dependencies and then run
python3 -m venv .venv
for a fresh virtual environment.