Forums

Using PYTHONPATH

Hello,

I have written a module that I would like my apps to be able to share. Is there any way in pythonanywhere that I can set the environment variable for PYTHONPATH to just simply type import mymodule? I don't want to use the sys,path.append hack.

You could add PYTHONPATH value to your ~/.bashrc file, it will be only read by the code that is run in the Bash environment (which reads your the .bashrc file), if you're running the code in tasks, you could probably prepend the setting of PYTHONPATH to the commad. Alternatively you could create a package from your module and install it with pip in your account / venvs that require it.

That sounds like an interesting idea - I want to use it both in my django (venv) environments as well as from bash/tasks.

Do you have any docs on how to do this? Haven't seen any.

With which part / idea do you need help?

I suppose it's not difficult in the Windows world. But being new to the platform, how do you set it both in the virtual environment and non-virtual environment persistently in bash?

My tasks and website can definitely make use of sharing the package.

Could you describe your use case? For example is it like you have module A, webapps B and C, and you want to use module A in B & C code, but also run it independently as a task? Or maybe it's module A and webapp B and you want to use A in B, but also in a task?