0

I am currently in the process of developing a module that I am using as a library to be imported in another project. I need a sane way that I can install this module in the python site packages in such a way that I don't need to reinstall it everytime I make changes to it. Currently, I am using sudo pip install --force-reinstall {BASE_FOLDER_FOR_MODULE}, but need to re run this command everytime I make any changes to the module code.

The little bit of info I've been able to find on the subject seems to indicate that while I can symlink the base folder for the module in the site-packages folder for my other project, that this may not necessarily be a good way to do it. Is symlinking the folder bad, and if so why? Is there an alternate (better) option?

Thanks

1 Answer 1

1

If the library is still under active development then consider adding it to environment variable PYTHONPATH. Directories in PYTHONPATH are appended to sys.path and are searched last when trying to find a module. Using PYTHONPATH means you only have to make minimal changes (set it in a config file source file or .bashrc file) for things to work. Once the library is finalised you can install it to the site-packages directory and remove it from PYTHONPATH.

Sign up to request clarification or add additional context in comments.

4 Comments

I'm trying to do this, and while I see my folder in list when I print out sys.path, I can't import the module. My folder structure is base_folder/src/folder1/all my code lives here. The setup.py file is located in the base folder. I've tried making PYTHONPATH to be both the base folder and folder1 in this example, and still can't load the module by its name'
Are you exporting PYTHONPATH? An environment variable is only visible to the current process unless it is exported. eg export PYTHONPATH=blah (for bash).
I added an export statement to my bash profile and made sure to source the profile before trying it
The .bash_profile is only executed once, at login. .bashrc is executed every time you open a new terminal. You will need to logout and login again for the changes in .bash_profile to take effect. Try setting PYTHONPATH on the command line and then running python -m my_module first though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.