我在OSX上并通过名为virtualenv
的{{1}}设置了一个python virtualfish
。在我的项目目录中激活ds-mapreduce-env
后,看起来选择了正确的venv
和pip
:
python
但是当我运行~/d/ds-mapreduce (venv) master ➜ which pip
/Users/cody/.virtualenvs/ds-mapreduce-env/bin/pip
~/d/ds-mapreduce (venv) master ➜ which python
/Users/cody/.virtualenvs/ds-mapreduce-env/bin/python
时,它不会按预期安装到虚拟环境中。但是,当我使用pip install
时,确实如此。
sudo
我猜这是某种权限问题,但我无法弄清楚。我安装了~/d/ds-mapreduce (venv) master ➜ pip install geonamescache
Requirement already satisfied (use --upgrade to upgrade): geonamescache in /usr/local/lib/python2.7/site-packages
~/d/ds-mapreduce (venv) master ➜ sudo pip install geonamescache
The directory '/Users/cody/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/cody/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting geonamescache
Installing collected packages: geonamescache
Successfully installed geonamescache-0.18
python
和brew install python
virtualfish
。我尝试删除并重新安装无效。
我的解决方案
我的问题出在我的pip install virtualfish
上。我PYTHONPATH
前置了/usr/local/lib/python2.7/site-packages
。删除它修复了问题!
答案 0 :(得分:1)
第一步是卸载全局安装的软件包:
pip uninstall -y geonamescache
通过检查/usr/local/lib/python2.7/site-packages/
确认已完全删除它。如果没有,请手动删除您在那里找到的任何相关碎屑。
下一步是更好地将您的虚拟环境“site-packages
与全局site-packages
隔离开来。将以下内容添加到~/.config/fish/config.fish
:
set -x PIP_REQUIRE_VIRTUALENV "true"
如果您打开一个新的终端会话,如果在没有激活的虚拟环境的情况下运行pip install geonamescache
,您现在应该会收到错误 - 这正是我们想要的。通过vf new ds-mapreduce-env
创建并激活新的虚拟环境并再次尝试相同的pip install geonamescache
调用,并将软件包安装到虚拟环境中。
由于这会阻止您在全局site-packages
中安装任何内容,因此您可能需要设置一个别名,以便覆盖此隔离并执行全局pip
操作。将以下函数添加为~/.config/fish/functions/gpip.fish
:
function gpip -d "Manage globally-installed Python packages"
env PIP_REQUIRE_VIRTUALENV="" pip $argv
end
有了这些,您可以(例如)通过以下方式升级您的全局包:
gpip install --upgrade setuptools pip wheel virtualenv
上述大部分内容已通过Tacklebox + Tackle(寻找pip
插件)解决,这些插件旨在为fish
环境轻松添加增强功能