[英]Best practice for upgrading Python modules
I've been learning Python for several months but now finding some problems with my 2.7 installation as I've looked into modules such as nltk.我已经学习 Python 几个月了,但现在我发现我的 2.7 安装存在一些问题,因为我已经研究了诸如 nltk 之类的模块。
However, when I want to list modules using help ("modules) I have the main error which I think explains the problem is:但是,当我想使用帮助(“模块”)列出模块时,我认为可以解释问题的主要错误是:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg/setuptools/command/install_scripts.py:3: UserWarning: Module numpy was already imported from /Library/Python/2.7/site-packages/numpy-override/numpy/__init__.pyc, but /Library/Python/2.7/site-packages/numpy-1.8.0.dev_5c944b9_20120828-py2.7-macosx-10.8-x86_64.egg is being added to sys.path
from pkg_resources import Distribution, PathMetadata, ensure_directory
I also receive the following error to do with deprecated modules:我还收到以下与弃用模块有关的错误:
/Library/Python/2.7/site-packages/statsmodels-0.5.0-py2.7-macosx-10.8-intel.egg/scikits/statsmodels/__init__.py:2: UserWarning: scikits.statsmodels namespace is deprecated and will be removed in 0.5, please use statsmodels instead
I'm still trying to get to grips with paths.我仍在努力掌握路径。 How can I avoid this issue in future?
我将来如何避免这个问题?
You have installed packages under your operating system Python library.您已经在操作系统 Python 库下安装了软件包。 This is big no no.
这是大不不。 What you should have done is to create an isolated, disposable, Python environment with virtualenv tool:
您应该做的是使用 virtualenv 工具创建一个隔离的、一次性的 Python 环境:
http://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of-python-software-with-virtualenv/ http://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of-python-software-with-virtualenv/
This way, when you upgrade your packages or need to get rid of them you can always reset the state of all of your Python packages by simply deleting the environment and creating new one.这样,当您升级包或需要删除它们时,您始终可以通过简单地删除环境并创建新环境来重置所有 Python 包的状态。
Python packages installed via pip or easy_install commands are easy to install, but impossible to uninstall...通过pip或easy_install命令安装的 Python 包很容易安装,但无法卸载...
But when the damage has already happened you nede to manually try to clean up /Library/Python/2.7/site-packages/ by deleting files by and trying not to destroy your system Python in the process.但是,当损坏已经发生时,您需要手动尝试清理 /Library/Python/2.7/site-packages/ 通过删除文件并尽量不要在此过程中破坏您的系统 Python。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.