简体   繁体   English

升级 Python 模块的最佳实践

[英]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...通过pipeasy_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.

相关问题 在 Python 中导入模块 - 最佳实践 - Importing modules in Python - best practice 延迟加载 Python 模块的最佳实践 - Best practice for lazy loading Python modules python中不同模块之间通信的最佳实践 - Best practice for communication between different modules in python 升级Django版本:最佳做法 - Upgrading Django Version: Best Practice 在Anaconda中安装Python模块的开发版本的最佳实践是什么? - What's the best practice for installing development versions of Python modules in Anaconda? Python记录了可重用模块的最佳实践,这些模块旨在包含在其他代码中 - Python logging best practice for reusable modules intended to be included with other code 在父子模块中导入祖父母模块的Python最佳实践 - Python best practice for importing grandparent module in parent and child modules 从任意VCS存储库安装python模块的最佳实践 - Best practice for installing python modules from an arbitrary VCS repository 将内部模块导入python中的另一个子目录的最佳做法是什么? - What is best practice for importing internal modules to another subdirectory in python? 在 Python 中使用导入模块编写自己的函数的最佳实践? - Best practice for writing own functions with imported modules in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM