Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to permanently append a path to Python for Linux?

Tags:

python

I know there are multiple solutions online, but some are for windows, some are environmental variable, etc..

What is the best way?

like image 711
TIMEX Avatar asked Dec 18 '22 05:12

TIMEX


2 Answers

Find your site-packages directory and create a new file called myproj.pth

Inside that file, put each directory you want to add, one per line like so:

/home/myuser/svn-repos/myproject
/home/myuser/svn-repos/SomeOtherProject

Python loads *.pth every time it runs, and imports all paths in each of those files.

In Ubuntu, that directory can often be found at /usr/local/lib/python2.6/dist-packages/

like image 94
Paul McMillan Avatar answered Jan 07 '23 09:01

Paul McMillan


I personally just define PYTHONPATH in ~/.bashrc, as for what's the "best" approach? I think that's hard to answer (or rather, there's no correct answer). It depends.

like image 37
hasen Avatar answered Jan 07 '23 10:01

hasen