VirtualEnv/Pip尝试在全球范围内安装软件包 [英] VirtualEnv/Pip trying to install packages globally

查看:110
本文介绍了VirtualEnv/Pip尝试在全球范围内安装软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑#2 解决方案;见下文.

我正在使用VirtualEnv在Flask中编写一个小型应用程序.这与我第一次做这件事相去甚远,但是这次和过去两次我都尝试过遇到相同的问题.当我. flask/bin/activate并尝试安装软件包时,例如pip install flup,它会一直在全局安装,而不是在VirtualEnv中安装.奇怪的是,它仅在我deactivate之后发生,并且在此情况下不一致.

I'm writing a small application in Flask using VirtualEnv. This is far from the first time I've done this, but the this time and past two times I've tried I've encountered the same problem. When I . flask/bin/activate and try to install a package -- pip install flup, for instance -- it keeps being installed globally, and not in the VirtualEnv. The weird thing is, it only happens after I deactivate, and it does so inconsistently at that.

就算是一次安装,我似乎也能够安装所需的所有东西,甚至偶尔在deactivate之后安装,但是经过一定的间隔后,它们就会停止工作,并且它开始尝试安装到我的全局Python site-packages中. (自然地,它在执行此操作时还要求获得许可.在我了解发生了什么之前,我试图用sudo强制执行此操作,以为我是偶然地sudo virtualenv flask -ing之类将其带到自己身上的,但是没有,它由于其他原因而走向全球.)

To wit, I seem to be able to install everything I need if I do it all at once, and even occasionally after I deactivate, but after a certain interval it just stops working and it starts trying to install into my global Python site-packages. (Naturally, it's also asking for permissions when it does this. Before I understood what was going on I tried to force it with sudo, thinking I'd brought it upon myself by accidentally sudo virtualenv flask-ing or something, but nope, it's going global for some other reason.)

我没有做任何有趣的事情,例如使用--system-site-packages参数,并且在VirtualEnv配置开始发生之前,我没有进行任何更改.第一次发生时,我把它归纳为a幸.现在,它变得非常烦人,因为我不想每次都卸载并重新安装所有内容,或者祈祷我会在引导脚本中考虑到我需要的所有内容.

I'm not doing anything funny like using the --system-site-packages argument, and I hadn't changed anything in my VirtualEnv configuration before it started happening. The first time it happened, I chalked it up to a fluke. Now it's becoming seriously irritating because I'm not in the mood to uninstall everything and reinstall it each time, or pray that I'll think of everything I need in a bootstrap script.

我不包含任何错误消息,因为它们不是(或似乎不是)特别有价值;只是requirement already satisfied一遍又一遍地对我大喊.

I'm not including any error messages because they aren't (or don't seem to be) particularly valuable; it's just requirement already satisfied yelling at me over and over.

编辑#1 我有点想知道这个问题了,但是我仍然没有解决方案.我在同一目录中创建了一个新的Flask项目,并在其中添加了cd -ed,激活了它的VirtualEnv等,然后运行了which pip.这是新的VirtualEnv的提示-正确的提示.我停用了cd -ed到我的原始项目,激活了VirtualEnv,然后运行了which pip.它吐出另一个项目的-新项目的-点子.我rm -r-编辑了新的测试项目,回到原来的位置,再次运行which pip,它吐出了/usr/local/bin/pip.哦.好吧.

Edit #1 I'm winnowing down the problem a little bit, but I still don't have a solution. I created a new Flask project in the same directory, cd-ed into it, activated its VirtualEnv, etc., then ran which pip. It was the new VirtualEnv's pip -- the right pip. I deactivated, cd-ed to my original project, activated VirtualEnv, and ran which pip. It spit out the other project's -- the new one's -- pip. I rm -r-ed the new test project, went back to the original, ran which pip again, and it spit out /usr/local/bin/pip. Oh. OK.

编辑#2:解决方案我可能没有找到确切的原因,但确实找到了解决方案. bin/activatebin/pip脚本本身也有所更改,可能是由于意外地同时运行两个VirtualEnv而引起的.之前从未发生过,连续发生了三次,这可能只是巧合.邓诺.

Edit #2: Solution I may not have figured out the exact cause, but I did find the solution. The bin/activate and bin/pip scripts themselves were altered somehow, possibly from accidentally running two VirtualEnvs at the same time(?). Maybe it's just coincidence that it happened three times in a row after never happening before. Dunno.

I cat -ed activate并且确定,在第42行上是

I cat-ed activate and sure enough, on line 42, was

VIRTUAL_ENV="/Users/chaseries/blueprint/python/flask2/flask"

代替

VIRTUAL_ENV="/Users/chaseries/blueprint/python/flask/flask"

我更改了它,再次运行which pip,并得到了正确的结果.尝试安装,获得了导致我进入bin/pip的堆栈跟踪信息,并发现其shebang错误.将其更改为正确的路径,一切正常.

I changed it, ran which pip again, and got the right result. Tried installing, got a stack trace that led me to bin/pip, and found its shebang was wrong. Changed it to the right path, and everything works perfectly.

推荐答案

我遇到了同样的问题.对我来说,原因是我的virtualenv路径中有空格.

I had the same problem. For me, the cause was that my virtualenv had spaces in the path.

将virtualenv移至无空间路径即可解决此问题.

Moving the virtualenv to a spaceless path solved the problem.

这篇关于VirtualEnv/Pip尝试在全球范围内安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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