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

Problem with importing oemof site packages #78

Open
pjutr opened this issue Feb 19, 2022 · 12 comments
Open

Problem with importing oemof site packages #78

pjutr opened this issue Feb 19, 2022 · 12 comments

Comments

@pjutr
Copy link

pjutr commented Feb 19, 2022

Hello oemof community. For my master thesis I should model a heat network and I would like to use oemof for this. However, I have been experiencing problems installing oemof and the site packages for a few days now. The errors occur when importing the oemof site packages (oemof.tools, oemof.outputlib, ... ), while these packages are installed according to the Anaconda environment (see image). I am using Spyder as my programming environment. It seems that when I run the oemof_examples in spyder it is unable to find and use the packages, even though they are correctly installed in this location.

When running the code: basic_example.py from v0..x of the example codes I get the following error:
"ImportError: cannot import name 'helpers' from 'oemof.tools' (C:oemof.tools)"

Similar errors occur when running the other sample code. This while the Solver is installed correctly (see testcode):


Solver installed with oemof:

cbc: working
glpk: not working
gurobi: not working
cplex: not working


oemof successfully installed.


I am new to this platform and could use all the help I can get! Thanks in advance.

oemof

@fwitte
Copy link
Member

fwitte commented Feb 19, 2022

@pjutr,

it‘s been quite a long time since I last used spyder, so I am not an expert here. But I remember that spyder needs to be installed to and started from the environment you installed solph. Also, it would be helpful, if you could provide a full list of packages installed in your environment. Also, try to run the example from the anaconda prompt. You need activate the environment conda activate environment-name, navigate to the folder with the examples and the run it python filename.py. Does that work?

Have a nice weekend

@pjutr
Copy link
Author

pjutr commented Feb 20, 2022

@fwitte
Thank you for the quick response.
When I follow your method i get the following error:

ImportError: cannot import name 'Node' from 'oemof.network' (C:\Users\Casper\anaconda3\envs\masterproef\lib\site-packages\oemof\network_init_.py)

@fwitte
Copy link
Member

fwitte commented Feb 20, 2022

Can you post a list of installed packages?

conda list --export > package-list.txt

What python version do you use?

@pjutr
Copy link
Author

pjutr commented Feb 20, 2022

My Spyder environment uses: Python 3.8.12

package-list.txt

@fwitte
Copy link
Member

fwitte commented Feb 20, 2022

I do not have access to a windows machine right now, I'll try to reproduce your installation and let you know once I have managed to.

@p-snft
Copy link
Member

p-snft commented Feb 21, 2022

Could yo specify which version of basic_example.py you use (v0..x) might be any. Most except one are expected not to work because the versions do not match.

@uvchik
Copy link
Member

uvchik commented Feb 21, 2022

package-list.txt

The package list shows that you have install the old oemof meta package in parallel. This old package does not work together with the new oemof-solph package. You could try to deinstall the oemof package and then reinstall oemof.solph and oemof.tools and oemof.network separately. You have to install each package the dependecy is not enough. If this does not work you can also create a fresh virtual environment or conda environment. Then you can install oemof-solph with pip install oemof.solph. Maybe this is even simpler than the first solution. Now the examples should work as expected.

@oemof-developer You can reproduce the error by installing oemof using pip install oemof and then solph with pip install oemof.solph. We may add this to our docs but it will become less important over the time. We could release a new version of oemof that will do something different than installing the old solph version.

@p-snft
Copy link
Member

p-snft commented Feb 21, 2022

To prevent this in the future: Could we just create a new oemof meta package that depends on the most recent versions of solph and tools?

@uvchik
Copy link
Member

uvchik commented Feb 22, 2022

To prevent this in the future: Could we just create a new oemof meta package that depends on the most recent versions of solph and tools?

I do not like the idea to strengthen the association that oemof is the same asoemof.solph. Installing a package that does nothing is strange but it would prevent the problems above. If someone installs oemof (thinking of solph) and want to execute examples, nothing will work. Asking in a forum will bring the solution that installing oemof.solph will solve it. This would be easier than the procedure above. Furthermore, the error message would be clearer, I guess something like Cannot import solph, module not found....

@pjutr
Copy link
Author

pjutr commented Feb 22, 2022

I am trying to run the basic_example.py code from V0.2x

I have tried both your methods but still get the same error. I created a new environment "Thesis" and installed the different packages separatly (oemof.solph and oemof.tools and oemof.network) via pip.
However, I still see an error appearing that the packages are not found (see image).

oemof

Could it be the paths? I don't understand why this path comes with the warning:
ImportError: cannot import name 'helpers' from 'oemof.tools' (C:\Users\Casper\AppData\Roaming\Python\Python38\site-packages\oemof\tools_init_.py).

While I have installed the packages in my environment "Thesis".

@p-snft
Copy link
Member

p-snft commented Feb 22, 2022

You are trying to run an example made for oemof v0.2 using oemof.solph v0.4. Just go to basic_example.py from v0.4x, that one should work.

Preventing the error in the future: You are right, introducing a meta package also has disadvantages. Also, the problem seems to be caused by the availability of examples for old releases. We could hide those.

@pjutr
Copy link
Author

pjutr commented Feb 22, 2022

Thank you guys. The examples are able to run without any problem. It seems like there where 2 reasons causing the problems for my case.

  1. like @p-snft says, I used the wrong version of the basic_example code...
  2. I updated my python version to 3.8 a few weeks ago and the "default working directory" was still set on "current working directory", so the program was not following the right path to installed packages.

Now the modeling can begin! :)

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

No branches or pull requests

4 participants