The environment variable PYTHONPATH is actually only added to the list of locations Python searches for modules. You can print out the full list in the terminal like this:
python -c "import sys; print(sys.path)"
Or if want the output in the UNIX directory list style (separated by :) you can do this:
python -c "import sys; print(':'.join(x for x in sys.path if x))"
Which will output something like this:
/usr/local/lib/python2.7/dist-packages/feedparser-5.1.3-py2.7.egg:/usr/local/lib/ python2.7/dist-packages/stripogram-1.5-py2.7.egg:/home/qiime/lib:/home/debian:/us r/lib/python2.7:/usr/lib/python2.7/plat-linux2:/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:/usr/lib/python2.7/dist-packages/PIL:/u sr/lib/python2.7/dist-packages/gst-0.10:/usr/lib/python2.7/dist-packages/gtk-2.0: /usr/lib/pymodules/python2.7Answer from Hubro on Stack Overflow
The environment variable PYTHONPATH is actually only added to the list of locations Python searches for modules. You can print out the full list in the terminal like this:
python -c "import sys; print(sys.path)"
Or if want the output in the UNIX directory list style (separated by :) you can do this:
python -c "import sys; print(':'.join(x for x in sys.path if x))"
Which will output something like this:
/usr/local/lib/python2.7/dist-packages/feedparser-5.1.3-py2.7.egg:/usr/local/lib/ python2.7/dist-packages/stripogram-1.5-py2.7.egg:/home/qiime/lib:/home/debian:/us r/lib/python2.7:/usr/lib/python2.7/plat-linux2:/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:/usr/lib/python2.7/dist-packages/PIL:/u sr/lib/python2.7/dist-packages/gst-0.10:/usr/lib/python2.7/dist-packages/gtk-2.0: /usr/lib/pymodules/python2.7
Just write:
just write which python in your terminal and you will see the python path you are using.
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>
Where is python installed on Linux
How do I find out my PYTHONPATH using Python? - Stack Overflow
How do I know python path on linux ubuntu? - Stack Overflow
Quick Question: How do I view Python's location in command prompt?
Videos
Hi, I have anaconda installed, so typing:
which python
just returns the anaconda path, however, I need to unearth the standard install location as a script is annoyingly asking for python2.7. Google unfortunately only tells you how to install it, and I know that, I've just forgotten where the binary is usually located on linux and google won't tell me that no matter what I type in.
UPDATE: Thanks guys, I found it looking in /usr/bin/ and /usr/local/bin/ and to my delight, it's not there, Just upgraded to Linux Mint 20 and there is python3.8. lovely.
You would probably also want this:
import sys
print(sys.path)
Or as a one liner from the terminal:
python -c "import sys; print('\n'.join(sys.path))"
Caveat: If you have multiple versions of Python installed you should use a corresponding command python2 or python3.
sys.path might include items that aren't specifically in your PYTHONPATH environment variable. To query the variable directly, use:
import os
try:
user_paths = os.environ['PYTHONPATH'].split(os.pathsep)
except KeyError:
user_paths = []
You can type which python on the ubuntu terminal and it will give the Python installed location path.
First, I hope you don't really set PYTHONPATH=/etc, /etc is for configuration files, not python libraries.
You can see what an environment variable is set to by using echo, e.g.: echo $PYTHONPATH. If the variable has not been set it will be blank. You can also use env to get a list of all environment variables, and couple with grep to see if a particular one is set, e.g. env | grep PYTHONPATH.
So I've been having trouble with Python and I want to know which installation I'm using (I have two user profiles on Windows, my old one and the one I made explicitly to code in, and they both have Python installed).
I tried looking it up, but it only led to this madness you see below:
Microsoft Windows [Version 10.0.19043.1348]
(c) Microsoft Corporation. All rights reserved.
C:\Users\willi>!type python
'!type' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\willi>type python
The system cannot find the file specified.
C:\Users\willi>type Python
The system cannot find the file specified.
C:\Users\willi>Python type
Python: can't open file 'C:\Users\willi\type': [Errno 2] No such file or directory
C:\Users\willi>Python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
>>> .quit
File "<stdin>", line 1
.quit
^
SyntaxError: invalid syntax
>>> quit
Use quit() or Ctrl-Z plus Return to exit
>>> quit()
C:\Users\willi>python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> !type Python
File "<stdin>", line 1
!type Python
^
SyntaxError: invalid syntax
>>> type
<class 'type'>
>>> type python
File "<stdin>", line 1
type python
^
SyntaxError: invalid syntax
>>> type Python
File "<stdin>", line 1
type Python
^
SyntaxError: invalid syntax
>>> type(Python)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Python' is not defined
>>>How do I view Python's location in command prompt?