How to move old libraries of previous version python to new version of python
I am using Ubuntu. I install newer version of python. But all my installed libraries such as imdbPy, NumPy, Cython etc. can run in previous version of python whose version number is 2.6.6.
When I import Cython in 2.6.6, tt works, but I try same thin开发者_JS百科g in 2.7.0+ version of python
import cython
occurs an error as following:
import cython
ImportError: No module named cython
What I need is to change default version of python which is used in bash. I think, I can handle it by modifying bash profile file. I also want to move all of these libs to appropriate place so that new version of python can reach them permanently.
Don't mess with your system installs - the package manager should be responsible for that. Make sure that when you install from source, you do it in a separate directory.
I install things in my home directory. I like jhbuild so this is what I use to maintain different versions of python side by side: https://thomas.apestaart.org/thomas/trac/browser/jhbuild/python
Running make from that checkout will build python 2.3-2.7 and create scripts to go into their environment:
[thomas@level ~]$ py-2.4
Entering interactive py shell /bin/bash
[py-2.4] [thomas@level ~]$ python
Python 2.4.5 (#1, Dec 16 2010, 18:51:06)
[GCC 4.4.4 20100630 (Red Hat 4.4.4-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Try using setuptools to reinstall the libraries. Actually, I recommend reinstalling instead of trying to use the old 2.6 libs with Python 2.7, since there may be some incompabilities.
You need to reinstall all the libraries for the new version.
I'd recommend that you first download pip and install it. After that you can install most packages with /path/to/Python27/bin/pip install <packagename>
, for example
/opt/python27/bin/pip install Cython
clearly a package management tool is the way to go, because they should be able to set all the stuff I'm about to mention (plus check compatibility and dependencies) but here's some stuff that might be helpful if you run into any problems with the package manager you choose:
before you make changes, check PATH
by using echo $PATH
in bash. The directories are listed in the order that they are searched.
you can determine which version of python is used in bash by changing the order of directories in PATH
such that the version you want appears first in PATH
.
For example, if you want a python version in opt/local/bin
rather than one in usr/local/bin
, you can set PATH
in your .bash_profile
or .bashrc
file with a line like this:
export PATH=opt/local/bin:$PATH
You can check the file path of the python bash is using with:
which python
(entered in bash)
As for the libraries, ensure that PYTHONPATH
in bash and sys.path
in python are set correctly, so that it can find the appropriate libraries, and uses the updated and compatible versions instead of the old ones. You can also create .pth files containing paths to directories that you want to add to sys.path
, and can use PYTHONSTARTUP
in bash to run a module at startup that sets sys.path
.
Unless you have a whole new set of libraries in a separate folder for the specific version of python, you may encounter problems, especially since many libraries will rely on others, and may therefore use outdated versions of each other.
If you have more than one module on sys.path
that uses the same name, they may conflict.
you can check the directory path of a python module you have imported like this:
import Cython
print Cython.__file__
Hopefully all of this will be taken care of by the package manager of your choice, but you can at least check your paths carefully if you encounter trouble.
精彩评论