HeloiseS / hoki

Bridging the gap between observation and theory
https://heloises.github.io/hoki/intro.html
BSD 3-Clause "New" or "Revised" License
47 stars 8 forks source link

[BUG] Hoki not importing from main directory #85

Closed J-Gleave closed 1 year ago

J-Gleave commented 1 year ago

Describe the bug Hoki can not be imported by linux terminal running python from main directory, however, can be running python after changing to the directory hoki was installed to.

To Reproduce Steps to reproduce the behavior:

  1. Hoki installed using the following code cd hoki pip install -e . 2a. Launch new terminal and run python. 3a. Run from hoki import load 4a. See error However, 2b. Launch new terminal, runcd hoki, then start python 3b. Run from hoki import load 4b. See no error.

Screenshots image Installing hoki to hoki directory.

image Obtaining error.

image No error

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

HeloiseS commented 1 year ago

Hi thanks for opening this issue. This is interesting. Does this also happen when you install hoki using pip directly rather than cloning the directory and doing the pip intall? I am trying to find contrasting behaviour so I can better narrow down the source of the bug

maxbriel commented 1 year ago

Hi! This is probably an issue with the installation of hoki. Hoki works from within the directory, because it's importing the files directly but does not load outside of it.

Given that you have successfully installed hoki, my suspicion is that your pip installs it to a different version of python than when you initiate python using the python command. This is a common problem with multiple python installs.

When installing hoki in the directory, try using: python -m pip install -e .

This should use the python version you initiated to install hoki.

If this does not work, can you please let me know the output of the commands python --version, pip --version , which python, and which pip.

J-Gleave commented 1 year ago

Hi.

Trying python -m pip install -e . didn't seem to work :(

The output for the commands listed are as follows:

python --version Python 3.9.13

pip --version pip 22.2.2 from /home/jamie/anaconda3/lib/python3.9/site-packages/pip (python 3.9)

which python /home/jamie/anaconda3/bin/python

which pip /home/jamie/anaconda3/bin/pip

Thanks

maxbriel commented 1 year ago

That looks like it should.

Offline, we solved this by uninstalling hoki as an editable version and reinstalling it using pip.

However, what causes this behaviour is unclear. Possible the resource_package?

HeloiseS commented 1 year ago

@J-Gleave have you managed to install hoki now?

If not and you are still struggling, you can add hoki to your python path by modifying your .bashrc file (this is not the recommended way to do things nowadays but it should work). Here is mine, you should replace the /home/fste075/ by the absolute path the the hoki directory (the top one, which is the directory you download when you clone this repo, not the hoki subdirectory within it)

export PYTHONPATH="${PYTHONPATH}:/home/fste075/hoki/"

note that for this to take effect you should restart your terminal or type bash and hit return to reload your settings

J-Gleave commented 1 year ago

Yes, I have managed to install hoki now. It was solved as above by reinstalling a non-editable version using pip.

HeloiseS commented 1 year ago

Great! I'll close the issue then :) thanks for being in touch. Please open up new issues if you encounter any problem we'd be happy to help!