[英]Python module import order
I have downloaded and installed the development version of Numpy from Github and at first this module is imported with a standard import. 我已经从Github下载并安装了Numpy的开发版本,起初该模块是通过标准导入导入的。 Somewhere along the line (package manager updates or other python package installs from git sources I suspect) Python imports revert to the Numpy module installed by the package manager.
沿途的某个地方(我怀疑git源中的软件包管理器更新或其他python软件包安装)Python导入恢复为软件包管理器安装的Numpy模块。
How do I get Python to import the modules I have installed from git sources? 如何获取Python以从git来源导入已安装的模块?
I would like to avoid having to modify the sys.path in every script. 我想避免必须在每个脚本中修改sys.path。
I run Ubuntu Gnome 14.10. 我运行Ubuntu Gnome 14.10。
The path is as follows: 路径如下:
>>> import sys
>>> sys.path
['',
'/usr/local/bin',
'/usr/local/lib/python2.7/dist-packages/matplotlib-1.5.x-py2.7-linux-x86_64.egg',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode',
'/usr/lib/python2.7/dist-packages/IPython/extensions']
Recommended way is off course, using VirtualEnv. 推荐的方法是使用VirtualEnv,这是当然的。 But as a suggestion, you can add the git numpy source to the pythonpath manually, before working on that module.
但是,作为建议,您可以在处理该模块之前将git numpy源手动添加到pythonpath中。
$ export PYTHONPATH=$PYTHONPATH:/YOUR/REPO/LOCATION
I used to do this before I learnt of virtualenvs ;) 在了解virtualenvs之前,我曾经这样做过;)
As suggested in comments above, it is highly recommended to use virtualenv module, because when you will have more that 1 project you will face the problem that different projects require different modules or different versions of one module. 如上面的注释中所建议,强烈建议使用virtualenv模块,因为当您拥有多个项目时,您将面临以下问题:不同的项目需要不同的模块或一个模块的不同版本。
Imagine you have 200 projects and each of them require some modules to work. 假设您有200个项目,每个项目都需要一些模块才能工作。 If you decide to share one of your project with anybody it will be a nightmare to determine which dependencies has this exact project and what modules are required for it to work.
如果您决定与任何人共享您的一个项目,那将是一场噩梦,要确定哪个依赖项具有这个确切的项目以及需要哪些模块才能工作。
So please check virtualenv and also virtualenvwrapper which makes work with virtualenv very comfortable. 因此,请检查virtualenv以及virtualenvwrapper ,这使virtualenv的工作非常舒适。 Both modules available for
pip install
, they are not complex, you will get hands on them very quick. 这两个模块都可以进行
pip install
,它们并不复杂,您将很快掌握它们。 Time spent to study them worth of benefit you will get. 花时间研究他们将获得的价值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.