简体   繁体   English

没有VirtualEnv的Python2.7中的站点包

[英]Site-Packages in Python2.7 without VirtualEnv

When I use pip install matplotlib --upgrade it runs and installs matplotlib and all dependicies, and at the end reads uninstalled version '1.3.1' . 当我使用pip install matplotlib --upgrade --upgrade时,它将运行并安装matplotlib和所有依赖项,最后读取已uninstalled version '1.3.1' Running python and matplotlib.__version__ outputs '1.3.1' again, even though it was just declared uninstalled. 运行python和matplotlib.__version__再次输出'1.3.1' ,即使它刚刚被声明为已卸载。 How do I switch which python I'm running from, which would hopefully be where pip is installing and updating packages? 如何切换运行的python,希望是pip安装和更新软件包的位置?

Edit: Running Mac OS 10.10.1, using python from bash. 编辑:从bash使用python运行Mac OS 10.10.1。

which pip returns /usr/local/bin/pip and which -a python returns which pip返回/usr/local/bin/pip以及which -a python返回

/opt/local/bin/python
/opt/local/bin/python
/Library/Frameworks/Python.framework/Versions/Current/bin/python
/Library/Frameworks/Python.framework/Versions/Current/bin/python
/Library/Frameworks/Python.framework/Versions/Current/bin/python
/Library/Frameworks/Python.framework/Versions/2.6/bin/python
/usr/bin/python

which I'm assuming is the problem. 我假设是问题所在。 I've deleted 2.6 before, but my Mac uses it and I had to restore my OS. 我之前已经删除了2.6,但是我的Mac使用了它,因此不得不还原操作系统。 How do I switch amongst them. 如何在它们之间切换。

Your problem appears to be that you have two or more Python 2.7 installations, and the first python on the PATH comes from one installation (the MacPorts version, at /opt/local/bin/python ), while the first pip on the PATH comes from a different one (you haven't said which, but I'd guess it's /usr/local/bin/pip , and it's attached to either the pre-installed Apple Python or yet another Python). 您的问题似乎是您有两个或多个Python 2.7安装,并且PATH上的第一个python来自一个安装(MacPorts版本,位于/opt/local/bin/python ),而PATH上的第一个pip来了来自另一个(您还没有说出来,但我想它是/usr/local/bin/pip ,它已连接到预安装的Apple Python或另一个Python)。

If you want to have lots of Pythons installed all over the filesystem and switch among them without using virtualenv , you just need to write some scripts with modify your PATH . 如果要在整个文件系统上安装大量Python,并在不使用virtualenv情况下在它们之间进行切换,则只需编写一些脚本并修改PATH (And your PYTHONPATH , if you use one… but hopefully you don't.) (还有您的PYTHONPATH ,如果您使用的是…,但希望您不要。)

But I wouldn't recommend that. 但我不建议这样做。 If you want to use the MacPorts Python: 如果要使用MacPorts Python:

  • Make sure you have the MacPorts pip installed (it should be in /opt/local/bin/pip ). 确保已安装MacPorts pip (应该在/opt/local/bin/pip )。 I don't know if MacPorts has a separate python-pip package, or expects you to install it manually , or otherwise. 我不知道MacPorts是否具有单独的python-pip程序包,或者期望您手动安装它 ,否则。
  • If you don't know how to rehash your shell cache, just open a new Terminal window after getting the MacPorts pip installed. 如果您不知道如何重新整理Shell缓存,只需在安装MacPorts pip之后打开一个新的Terminal窗口。 Or, to be safe, just explicitly use /opt/local/bin/pip until the next time you logout and back in. 或者,为了安全起见,只需明确使用/opt/local/bin/pip直到下次注销并重新登录。
  • When you write scripts, you may want to #!/opt/local/bin/python instead of #!/usr/bin/env python . 编写脚本时,您可能希望使用#!/opt/local/bin/python而不是#!/usr/bin/env python
  • Uninstall every other Python except the MacPorts one and the pre-installed Apple ones. 卸载除MacPorts和预先安装的Apple之外的所有其他Python。
  • Any packages you accidentally installed for other Python installations, just reinstall them for MacPorts. 您为其他Python安装意外安装的所有软件包,只需为MacPorts重新安装即可。 Also, you should usually check for ports first, like port install python-ipython or port install python27-ipython , and only fall back to pip if there is no portfile. 另外,通常应该首先检查端口,例如port install python-ipythonport install python27-ipython ,并且只有在没有portfile时才回退到pip

As a side note, many people who have this problem also have MacPorts colliding with Homebrew (or sometimes Fink, gentoo-alt, or other package managers, but none of them are very common nowadays). 附带说明一下,许多有此问题的人也使MacPorts与Homebrew冲突(有时甚至是Fink,gentoo-alt或其他软件包管理器,但如今它们都不是很常见的)。 If you're using two such package managers, you really, really shouldn't be unless you know what you're doing. 如果您正在使用两个这样的程序包管理器,那么除非您知道自己在做什么,否则就不应该这样做。 I'd disable one entirely (at least take it off your PATH, if not uninstall it). 我会完全禁用一个(如果不卸载,至少要从PATH中删除它)。 You will likely have to rebuild a bunch of stuff after you do so, but it's better than having a bunch of stuff that kind of sometimes works… 这样做之后,您可能必须重建一堆东西,但是总比拥有一堆有时会起作用的东西要好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何手动将文件夹复制到/app/.heroku/python/lib/python2.7/site-packages/? - How to manually copy folder to /app/.heroku/python/lib/python2.7/site-packages/? 如果从python2.6导入要与python2.7一起使用的站点包,可能会发生问题? - Issues that could happen if importing site-packages from python2.6 to be used with python2.7? 如何忽略〜/ .local / lib / python2.7 / site-packages中的python模块? - How to ignore python module in ~/.local/lib/python2.7/site-packages? 如何将Python2.6站点包移动到Python2.7中? - How can I move my Python2.6 site-packages into Python2.7? ImportError:dlopen(/usr/local/lib/python2.7/site-packages/_geoslib.so - ImportError: dlopen(/usr/local/lib/python2.7/site-packages/_geoslib.so 如何在Linux下的/usr/local/lib/python2.7/site-packages下安装Pip - how to Install Pip under /usr/local/lib/python2.7/site-packages in Linux 找不到:/lib/python2.7/site-packages/tensorflow/tensorboard/lib/svg/summary-icon.sv - Not found : /lib/python2.7/site-packages/tensorflow/tensorboard/lib/svg/summary-icon.sv “/lib/python2.7/site-packages/不支持.pth文件”在MacOS上安装pip - “/lib/python2.7/site-packages/ does NOT support .pth files” installing pip on MacOS Python OSX - /usr/local/lib/python2.7/site-packages/easysnmp/interface.so中的平面命名空间 - Python OSX - flat namespace in /usr/local/lib/python2.7/site-packages/easysnmp/interface.so 安装djangorestframework时出现错误-权限被拒绝:'/ usr / lib / python2.7 / site-packages / djangorestframework-3.6.3.dist-info' - Getting Error while installing djangorestframework - Permission denied: '/usr/lib/python2.7/site-packages/djangorestframework-3.6.3.dist-info'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM