简体   繁体   中英

Modify PYTHONPATH to install packages into new “site-packages” path

I am working on an EC2 VM running Linux (I'm fairly new to Linux and Bash) which comes installed with Python 2.6. I upgraded to Python 2.7. When I try to install new modules, they install in /usr/lib/python2.6/site-packages but I need to change this to install in /usr/lib/python2.7/site-packages . I've tried a bunch of different ways to update the PYTHONPATH which I've found in various other post on Stackoverflow and other sites, but to no avail. Some I've tried are:

PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/site-packages export PYTHONPATH

PYTHONPATH="/usr/lib/python2.7/site-packages:$PYTHONPATH"

How can I update the install path to the new 2.7 path?

You covered how Python 2.7 was installed (which is a manual installation), how are you installing your modules?

If you sudo yum install <python-package> , you are going about this using system level (distribution specific) way of getting packages installed, which means it will only put packages in the system python location, in your case in the site-package directory in python2.6.

If you had used sudo pip install <python-package> , it should possibly work since you completely destroyed the default python installation which yum might have need (refer to Upgrade python without breaking yum ).

With virtualenv , you can specify isolated, local locations for which you can install python packages to, isolating them from system level and you can fix a virtualenv to any available versions of python on your system, guaranteeing the right sets of libraries with the right sets of packages with all the correct versions (for python and the packages) specific to the needs of a particular application, which means you don't have to deal with the system/distribution level python path issues as that can be a huge source of headache. For example, on the system level you have a package by your distro that depends on some old versions of sqlalchemy, but in your actual application you need the most recent version, with virtualenv you can mask out the system level package and have the latest version installed locally there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM