Reputation: 7681
I'm writing a Python package and I have the code in my Documents
folder under a subfolder named myPackage
(for sake of argument).
Whilst developing the modules in this package I've been writing test code at the bottom of the script and running/adding/modifying as the code develops. I essentially now want to test my code from outside the package now (because of a weird bug that would be essentially impossible to explain) by writing other scripts that use myPackage in the way that its intended to be run.
The problem is that the code is not importable from its current location and I don't want to add it to the PythonPath
variable because this will cause namespace clashes down the line, after installing in the site-packages directory using PyPI.
So my question is how do other people deal with this problem?
Upvotes: 1
Views: 76
Reputation: 1556
Check out Python VirtualEnv, it does exactly what I think you want. You can create new virtual environments for python with their own tool versions and path variables. Any changes made to that environment, stay in that environment. You can activate a virtual environment as desired, then deactivate it to go back to your native environment, or switch to another virtual environment.
To install it, most Python developers use pip. Install pip first using the instructions here.
sudo apt-get install python-pip
Then install virtualEnv:
pip install virtualenv
Read the user guide for virtualEnv at the Hitchhiker's Guide to Python
Upvotes: 2