As per my reserach on the topic, when we import a Python module, Python searches for the module in following order:
- Built in Python modules
- sys.path entries (current working directory + PYTHONPATH environment variable)
- Some installation specific default folders (don't know that these are, possible site-packages etc?)
In this flow, can we manipulate this order somehow so that Python looks for a specific folder before checking current working directory? I'm specifically trying to achieve this in the context of a wsgi application.
1 Answer 1
Well, I'm not so sure about changing the order of importing because, in my opinion, the order depends on how the language itself is written but what you can do is this maybe-
sys.path = ['/path/to/application/app/folder'] + sys.path
which will allow you to add firstly the module that you created to the path array.
pipenvorvirtualenvfor your project then the solution should be through that, rather than working around it. The whole purpose of a virtual environment is to be able to use different versions of Python and/or libraries for different projects, so I'd be very surprised if there's no way to set up a virtual environment with the right version of this module, using those tools.