Closed DQuanR2 closed 5 years ago
It looks like you have a file named CoolProp/CoolProp.py
. You can't do that, because then Python imports from that file instead of the library in the site-packages
folder. Try renaming that folder and file, and see if it fixes the problem.
Thanks a lot for the quick response.
I changed the name but I still get a problem when importing CoolProp.
I get this error:
runfile('/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/Simulacion/Test.py', wdir='/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/Simulacion') Traceback (most recent call last):
File "
File "/home/sofiapaz/anaconda3/envs/thermostate/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile execfile(filename, namespace)
File "/home/sofiapaz/anaconda3/envs/thermostate/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/Simulacion/Test.py", line 8, in
ImportError: bad magic number in 'CoolProp': b'\x03\xf3\r\n'
What if you run that file from the terminal, /path/to/anaconda/envs/thermostate/bin/python "/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/Simulacion/Test.py"
? Can you be more specific about how you installed CoolProp, including the exact commands you used?
The "bad magic number" error results from having incompatible .pyc
files in the module you're trying to import.
A potential fix is to go to the top level CoolProp directory and delete all the *.pyc
files in it and all its subdirectories. This will let Python recreate .pyc
files that are compatible with your current version of Python.
Thank for the responses. I tried deleting the .pyc files, but it didnt work. Then I deleted everything and did a fresh installation. Seems to be working now.
Thanks a lot!
Glad it works now!
I am not able to run any script outside the console (I have tried with Spyder and Sublime Text).
I followed the instructions for installing it. First I did it through pip where I tried to install only CoolProp.
And then I created a conda environment as suggested.
In both cases I only got CoolProp to work in the console but not in Spyder. I looked at the Python version used in the thermostate environment, copied the path and pasted it in spyder (tools -> preferences -> Python interpreter). However, I continue to get the same error message.
Code sample, preferably able to be copy-pasted and run with no changes
import CoolProp.CoolProp as CP fluid = 'Water' pressure_at_critical_point = CP.PropsSI(fluid,'pcrit') vL = 1/CP.PropsSI('D','P',1e5,'Q',0,fluid) vG = 1/CP.PropsSI('D','P',1e5,'Q',1,fluid)
Expected behavior
Actual behavior, including any error messages
Python 3.7.2 (default, Dec 29 2018, 06:19:36) Type "copyright", "credits" or "license" for more information.
IPython 7.3.0 -- An enhanced Interactive Python.
runfile('/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/CoolProp/CoolProp.py', wdir='/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/CoolProp') Traceback (most recent call last):
File "", line 1, in
runfile('/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/CoolProp/CoolProp.py', wdir='/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/CoolProp')
File "/home/sofiapaz/anaconda3/envs/thermostate/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile execfile(filename, namespace)
File "/home/sofiapaz/anaconda3/envs/thermostate/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/CoolProp/CoolProp.py", line 8, in
import CoolProp.CoolProp as CP
File "/home/sofiapaz/Dropbox/TU Delft/Cursos/Cursos Q3/ME45160 Advanced Applied Thermodynamics/CoolProp/CoolProp.py", line 8, in
import CoolProp.CoolProp as CP
ModuleNotFoundError: No module named 'CoolProp.CoolProp'; 'CoolProp' is not a package
Thermostate version, Python version, OS version
Thermostate version: 0.5.3 Python: 3.7.2 OS: Linux (Ubuntu 18.04)
Thank you very much