1

I'm developing a python module that is currently closed-source and cannot go on pip (not my choice) for this example I'll refer to it as private_module. This module relies on another module that I'm also developing that is available on pip I'll refer to it as public_module. Here is the problem private_module and the development version of public_module are in a directory on a windows server that I shared with co-workers. The computers that need to access the code have variable file permissions for their variable flavors of python meaning, it is very difficult to pip install ANYTHING but at the same time there may be lingering versions of both private_module and public_module in their site-packages directory. Also assume that all users have no programming experience and even if they did the computers would not be able to install packages with pip without admin privileges.

The directory structure can be represented like so:

  • C:\Program Files\Anaconda3\lib\site-packages\[outdated public and private modules]

  • F:\PythonModules\exp\[new public and private modules]

I've tried the following and it works perfectly if the modules have not been installed into pip but the modules that are installed in pip appear to be loaded in favor over the other which makes sense.

import os
staging = [r"F:\PythonModules\exp"]

for path in staging:
    if os.path.isdir(path):
        sys.path.append(path)

Is there a way that I can load the new public and private modules over their counterparts that may be in site-packages?

4

1 回答 1

2

This is somewhat of a hacky workaround but it should work in your case - you can add the private modules at the beginning of sys.path, so it will be read before the public pip version. Something like this:

import sys
sys.path.insert(0,"F:\PythonModules\exp")
于 2018-03-06T21:07:06.250 回答