1

We are working on writing some modules and centralizing them on our local network.

As suggested here: Import from network

I altered my PYTHONPATH to point to the network location.

Problem is that when I run the python shell, import and do: print my_mod.__file__ it's still pointing to my local directory.

Is there any way to import from the network location instead of locally, but keeping both links so I can work on the local?

Thanks!

Community
  • 1
  • 1
Onilol
  • 1,315
  • 16
  • 41

1 Answers1

1

There can be various things that make it not do what you expect, for instance:

  • Setting PYTHONPATH does not make it search there first, python will still look in your current directory before anywhere else.
  • Having the particular module installed in your local site-packages as well can cause it to be imported from there first if it uses a .pth file or some other import trickery.
  • Make sure you don't have any .pyc files in your local directory that are picked up for what you're importing.

You can check the paths that are searched in order by issuing import sys; print(sys.path) in your python shell.

The solution is perhaps to put your network location manually as first element in sys.path:

import sys
sys.path.insert(0, "/network/modules/location")
import thing_you_want
Irmen de Jong
  • 2,739
  • 1
  • 14
  • 26