6

I added $PYTHONPATH permanently via .bashrc like this

export PYTHONPATH=$PYTHONPATH:/path/to/python-sdk

and now when I start python, it doesn't show up in sys.path` and the libraries can't be imported. I know I could add it in python like this, but I want it to be permanently added.

I am using Linux Mint 19.2, kernel Linux 4.15.0-54-generic and Python 2.7.15+.

Edit: Unfortunately the other topic does not help me, because, even though i am using $PYTHONPATH, i cannot import the packages lying in the defined path. I want to permanently add this path and normally it works like this, but $PYTHONPATH doesn't seem to work at all.

Edit 2: This is the command line, when I try to use $PYTHONPATH:

$ export export PYTHONPATH=$PYTHONPATH:/opt/nao/python-sdk/lib/python2.7/site-packages
$ python
Python 2.7.15+ (default, Oct  7 2019, 17:39:04) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import naoqi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named naoqi
$ sudo ls /opt/nao/python-sdk/lib/python2.7/site-packages/             
allog.py   almathswig.py      inaoqi.pyc  naoqi.py   README
allog.pyc  _almathswig.so     _inaoqi.so  naoqi.pyc  vision_definitions.py
_allog.so  expressiveness.py  motion.py   qi
almath.py  inaoqi.py          motion.pyc  _qi.so

1 Answers1

2

I'm running Mint 19.3 and kernel version 4.15.0-106-generic - so not far off from you.

(python3-venv) me@mycomp:chap10-Batteries_Included$ cat/etc/*release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=19.3
DISTRIB_CODENAME=tricia
DISTRIB_DESCRIPTION="Linux Mint 19.3 Tricia"
...
(python3-venv) me@mycomp:chap10-Batteries_Included$ uname -r
4.15.0-106-generic

running in a Python 3 virtual environment. I'm working on "Beginning Python, From Novice to Professional" by Magnus Lie Hetland and got to Chapter 10 where it talks about this very thing. When I first get into my shell, I find nothing assigned to $PYTHONPATH either:

(python3-venv) me@mycomp:chap10-Batteries_Included$ echo $PYTHONPATH

(python3-venv) me@mycomp:chap10-Batteries_Included$

So I do what is suggested everywhere on the web, and in the book($PWD being my working directory, which happened to be the directory I wanted added):

(python3-venv) me@mycomp:chap10-Batteries_Included$ export PYTHONPATH=$PYTHONPATH:$PWD
(python3-venv) me@mycomp:chap10-Batteries_Included$ echo $PYTHONPATH
:/home/me/Documents/CodingProjects/python/Beginning-Python/book/chap10-Batteries_Included
(python3-venv) me@mycomp:chap10-Batteries_Included$

And there we go, it's there:

(python3-venv) me@mycomp:chap10-Batteries_Included$ python -O
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, pprint
>>> pprint.pprint(sys.path)
['',
 '/home/me/Documents/CodingProjects/python/Beginning-Python/book/chap10-Batteries_Included',
 '/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/home/me/python3-venv/lib/python3.6/site-packages']
>>> 

I noticed, and would have commented had I been able to without having 50 points on here, that you have export export PYTHONPATH=$PYTHONPATH:.... - you only need export once. You can add this export PYTHONPATH=... to your ~/.profile to make it permanent, too. I hope this helps.

JayRugMan
  • 116