Pycharm+external libraries

I am trying to run PyCharm. I have created a project in which the python files add pyfmi module from Jmodelica. Now this is where it gets confusing, Jmodelica provides a python 2.7 shell environment where it sets the path and installation of its relevant plugins such as pyfmi. The question is: How do I add this information to my project. I have tried creating a new virtual environment where path to python 2.7 executable given by Jmodelica in the run configuration, but with no luck. If tbe question os vague, please let me know which information should I provide to make the question more clear. Thanks.

10 comments

Hi,

PyCharm doesn't support Jmodelica natively as it does Anaconda for example. You can try running Jmodelica shell, then print the contents of PATH and PYTHONPATH from it. Then start system terminal, overwrite the contents of PATH and PYTHONPATH with those from Jmodelica environment, and start PyCharm from this terminal session. I know this sounds cumbersome, but you can start by trying this. 

Also, you can try adding the necessary content roots to the project structure in the settings, or interpreter paths:

https://www.jetbrains.com/help/pycharm/python-interpreters.html

https://www.jetbrains.com/help/pycharm/project-structure-dialog.html

0

Thank you. I did that. you can see my interpreter setting and also my python path, which is similar to what JModelica has in its own shell. However, I now get another error.

 

 

0

Please see this comment:

https://stackoverflow.com/a/51374827/10895914

I suspect that is 32-bit vs 64-bit compatibility issue. Please ensure that you're using the interpreter that comes with JModelica.

In fact, you should try creating a new system interpreter (not virtual environment), point it to the one bundled with JModelica, and test the workaround with paths from my previous message again.

Please let me know how it goes.

0

Thanks, but I still get the same error which says that there is no binaries for this version. am showing you now again my pycharm's PATH and PYTHONPATH and you can see that it is exactly similar to J Modelica's python shell, which is placed at the root of the python64.exe given at the root of the folder. 

Also, as you suggested, I created a new system interpreter (not virtual environment), regarding the interpreter to point towards JModelica's bundled one, I pick the following location JModelica\Python27\Python64\python.exe. I think it's the right interpreter. 

I looked at the link you provided, and as a workaround I downloaded the pre-built PYFMI binaries and included in PyCharm's PYTHONPATH, but no luck. I don't know why it gives this error, when clearly there are dll available in that folder. 

 

0

Can you please try running the same script directly with the interpreter, outside of IDE? (ensuring that all the paths are included in the environment) ?

If the issue appears to be not isolated to IDE, you might have a good chance asking Jmodelica developer / community.

0

Yes, that works. I could run the script perfectly from there. I just wanted to use nice interactive debugging options from Pycharm

0

Please also try additionally the following trick:

1. Open the python console settings in PyCharm

2. Create environment variables PATH and PYTHONPATH, and for their values paste the contents of those variables from Jmodelica environment

3. Repeat the same for run/debug configuration

Run the script. Does it change anything?

0

I tried it. No change...

 

It still says, " The FMU contains no binary for this platform." I wonder how is it then running in the JModelica's own shell.

It searches in these files actually:

self.model = load_fmu(fmu_location)
File "src\pyfmi\fmi.pyx", line 7842, in pyfmi.fmi.load_fmu (src\pyfmi\fmi.c:90218)
File "src\pyfmi\fmi.pyx", line 2541, in pyfmi.fmi.FMUModelCS1.__init__ (src\pyfmi\fmi.c:32169)
File "src\pyfmi\fmi.pyx", line 1229, in pyfmi.fmi.FMUModelBase.__init__ (src\pyfmi\fmi.c:16722)

where are these files btw? I couldn't find them.

Just a note, my FMIL_HOME file points to the pre-built binaries which were pointed out by one of the users in the forum you mentioned above. 

0

And also please clarify: sometimes I see both forward and backslashes in the path, when it shows on the console after I run the file.

0

Using both forward and back slashes is acceptable in Windows environment, that's most likely not related to the current issue.

Please open python console in your PyCharm project and show the output of:

 

import sys

sys.executable

0

Please sign in to leave a comment.