Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible solution to PYTHONPATH problem #173

Open
leander-j opened this issue Mar 21, 2022 · 0 comments
Open

Possible solution to PYTHONPATH problem #173

leander-j opened this issue Mar 21, 2022 · 0 comments

Comments

@leander-j
Copy link

As of now, before running a study script for the first time (e.g. in a new terminal) the PYTHONPATH variable needs to be set by running export PYTHONPATH="." on Unix or set PYTHONPATH = <path> on Windows. The specified path then gets added to sys.path which Python uses for locating its imports.

One issue is that you need to set this every time you start a new terminal.
Another issue is that "." is a relative path, so if you are working in another directory it does not work any more.

The following code adds the absolute pycopancore path directly to sys.path if added in a study script (that is located in the studies folder).

from os.path import dirname
import sys
sys.path.insert(0, dirname(dirname(__file__)))

Maybe it makes sense to add this to run scripts in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant