PYTHONPATHis an environment variable which you can set to add additional directories where python will look for modules and packages. e.g.:# make python look in the foo subdirectory of your home directory for # modules and packages export PYTHONPATH=${PYTHONPATH}:${HOME}/fooHere I use the
shsyntax. For other shells (e.g.csh,tcsh), the syntax would be slightly different. To make it permanent, set the variable in your shell's init file (usually ~/.bashrc).Ubuntu comes with python already installed. There may be reasons for installing other (independent) python versions, but I've found that to be rarely necessary.
The folder where your modules live is dependent on
PYTHONPATHand where the directories were set up when python was installed. For the most part, the installed stuff you shouldn't care about where it lives -- Python knows where it is and it can find the modules. Sort of like issuing the commandls-- where doeslslive?/usr/bin?/bin? 99% of the time, you don't need to care -- Just uselsand be happy that it lives somewhere on yourPATHso the shell can find it.I'm not sure I understand the question. 3rd party modules usually come with install instructions. If you follow the instructions, python should be able to find the module and you shouldn't have to care about where it got installed.
Configure
PYTHONPATHto include the directory where your module resides and python will be able to find your module.
PYTHONPATHis an environment variable which you can set to add additional directories where python will look for modules and packages. e.g.:# make python look in the foo subdirectory of your home directory for # modules and packages export PYTHONPATH=${PYTHONPATH}:${HOME}/fooHere I use the
shsyntax. For other shells (e.g.csh,tcsh), the syntax would be slightly different. To make it permanent, set the variable in your shell's init file (usually ~/.bashrc).Ubuntu comes with python already installed. There may be reasons for installing other (independent) python versions, but I've found that to be rarely necessary.
The folder where your modules live is dependent on
PYTHONPATHand where the directories were set up when python was installed. For the most part, the installed stuff you shouldn't care about where it lives -- Python knows where it is and it can find the modules. Sort of like issuing the commandls-- where doeslslive?/usr/bin?/bin? 99% of the time, you don't need to care -- Just uselsand be happy that it lives somewhere on yourPATHso the shell can find it.I'm not sure I understand the question. 3rd party modules usually come with install instructions. If you follow the instructions, python should be able to find the module and you shouldn't have to care about where it got installed.
Configure
PYTHONPATHto include the directory where your module resides and python will be able to find your module.
PYTHONPATHis an environment variable- Yes (see https://unix.stackexchange.com/questions/24802/on-which-unix-distributions-is-python-installed-as-part-of-the-default-install)
/usr/lib/python2.7on Ubuntu- you shouldn't install packages manually. Instead, use pip. When a package isn't in pip, it usually has a setuptools setup script which will install the package into the proper location (see point 3).
- if you use pip or setuptools, then you don't need to set
PYTHONPATHexplicitly
If you look at the instructions for pyopengl, you'll see that they are consistent with points 4 and 5.
The site module documentation and Modifying Python's Search Path seem to be what you're looking for.
As far as I understand it, those entries are being added to sys.path by:
/usr/lib/python2.6/site.py/usr/lib/python2.6/dist-packages/site.py
(Change 2.6 to your version of Python.)
The easiest way to change it is to add a file /usr/local/lib/python2.6/dist-packages/site-packages.pth containing ../site-packages.
Alternatively, maybe you can teach the package to use site.getsitepackages()?
I'd like to summarize my findings about python's path modification. There are two ways to do it.
- .pth file
PYTHONPATH
Any .pth file which is found on the default path (see bellow) will get its content included into sys.path.
Format of said .pth file is simple: one (folder) path per line. Surprisingly, the paths can be absolute or relative to the .pth file.
Default path is where the interpreter resides and <some-prefix>/lib/python<version>/site-packages where <some-prefix> is usually /usr/.
PYTHONPATH is environmental variable of your operating system. On unix systems you list them by env. Global modification of such variables is done through .sh scripts inside /etc/profile.d/ folder as mentioned by @TestUser16418.
Sys.path is included in the current directory by default
Does changing default python path to anaconda python affect software centre
path - Changing default python to another version - Stack Overflow
How to get the "Downloads" folder path on Windows
Videos
I'm assuming that when you installed anaconda 2, you manually set the PYTHONPATH environment variable, by putting something like
PYTHONPATH=/home/user/anaconda2/python
export PYTHONPATH
in your .bash_profile or .bash_rc.
But since you deleted the /home/user/anacanda2/ directory, that path no longer exists.
Thus you want to change PYTHONPATH to point to the executable in /usr/lib, by changing the above to
PYTHONPATH=/usr/lib/my_python_distribution
export PYTHON
execute the command:
echo $PATHroot1@master:/usr/lib/python2.7$ echo $PATH /home/root1/anaconda3/bin:/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8.0_74/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/root1/NAI/hadoop-2.7.3/binRemove your anaconda3 from your path variable that is
/home/root1/anaconda3/bin:Again set PATH variable with remaining information like below
export PATH=/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8.0_74/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/root1/NAI/hadoop-2.7.3/binExecute python command and should redirect to your python interpreter
root1@master:/usr/lib/python2.7$ python Python 2.7.14 (default, Sep 18 2017, 00:00:00) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
First question:
which python though its usually /usr/bin/python for the 2.7
Second question:
From a terminal & python2.7: python2.7 yourfile.py.
Simailarly for 3.2: python3.2 yourfile.py though 3.2 isn't installed by default. (You can apt-get install python3.2.)
What python yourfile.py will do depends on which alternative is used for your python interpreter. You can change that by issuing update-alternatives python as root (or by using su).
Third question:
Environment variables are shell dependent, though you can write them out with echo $variable and set them with variable=value (from bash). The search path is simply called PATH and you can get yours by typing echo $PATH.
I hope this was helpful.
If you want to find the location of a program you can just use whereis <program>.
In your case run:
whereis python2.7
whereis python3.2
For finding every file that apt-get has copied for installation use:
dpkg -S python2.7
dpkg -S python3.2
But maby it is recommend to save it in a textfile, because the output is to large.
dpkg -S python2.7 >log.txt
gedit log.txt
for running .py file with python 3.2
python3.2 <file.py>
Since you have Linux, and if you want to simply type "python" instead of "python3" in order to run Python programs, a solution is simply to define an alias in you shell configuration file (.bashrc, etc.). For Bourne shells, it should be something like
alias python=python3
(or whatever your Python 3 name is).
This way, you do not have to change anything on your system, so this solution should quite innocuous and it should not break your system.
You really don't want to change what python points to, because some programs might expect Python 2, and break.
The solution is to use virtualenv: create an isolated Python 3 environment (with the -p python3 option), activate it, and you're good to go.
It's not good to change the default python. Many system programs depends on python2 not python3. if you want to use python3, you just type the command python3.
The PYTHONPATH doesn't have much to do with it. It just tells the Python interpreter, whichever interpreter runs, where to find extra modules you want to load.
But either way, changing the default version on your system is dangerous, as other commenters have observed. You stand the risk of breaking existing package that are built against Python2 and use /usr/bin/env python to find their interpreters.
In fact, that's the wrong way to phrase it. Changing the default version of Python will break your entire Ubuntu system and cause lots of programs to just not work. It's also completely unnecessary.
But since you asked, you just do this:
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.2mu /usr/bin/python
Happy crashing!