当前位置: 动力学知识库 > 问答 > 编程问答 >

git - 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. 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.

How do I get Python to import the modules I have installed from git sources?

I would like to avoid having to modify the sys.path in every script.

I run 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. But as a suggestion, you can add the git numpy source to the pythonpath manually, before working on that module.

$ export PYTHONPATH=$PYTHONPATH:/YOUR/REPO/LOCATION

I used to do this before I learnt of 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.

Imagine you have 200 projects and each of them require some modules to work. 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. Both modules available for pip install, they are not complex, you will get hands on them very quick. Time spent to study them worth of benefit you will get.

分享给朋友:
您可能感兴趣的文章:
随机阅读: