0

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']
2
  • 4
    Are you using virtualenv? If you're not, you should be. Commented Dec 11, 2014 at 10:37
  • Agreed with Daniel. Virtualenv is the tool you need to avoid such problems. Commented Dec 11, 2014 at 10:39

2 Answers 2

1

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 ;)

Sign up to request clarification or add additional context in comments.

1 Comment

I will certainly take a look at virtualenv. In the mean time the above suggestion of changing PYTHONPATH does not work because even if I insert the repo before $PYTHONPATH as the package installed locations are still inserted prior to PYTHONPATH in sys.path.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.