[Tutor] sys.path.append import python3 not working

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Feb 5 12:58:46 CET 2014


On 5 February 2014 11:51, Tim Golden <mail at timgolden.me.uk> wrote:
> On 05/02/2014 11:46, Ian D wrote:
>> Ok even more strangely it is working in the original location.
>>
>> Am now not 100% sure that I have the folder structure correct.
>>
>> I will keep a eye on it.
>
> You might want to consider whether your approach is the best. One
> usually appends to sys.path when there's something dynamic about the
> location of modules (eg for a plugin mechanism). If your library modules
> are always in, say, d:/modules then just set up a PYTHONPATH env var
> with that in it; or use a .pth file in your python directory. I do the
> latter, altho' it's frowned upon by some for reasons I've never entirely
> understood.

Another option is to place it in site-packages. If you don't want to
use the system site packages you can always use the one in your user
directory. In my case on Ubuntu that's in
~/.local/lib/pythonX.Y/site-packages/

$ cat ~/.local/lib/python2.7/site-packages/mymod.py
print("This is my mod installed in my user site-packages")
$ python2.7
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mymod
This is my mod installed in my user site-packages


Oscar


More information about the Tutor mailing list