I am trying to run the following code:
import pymc as pm
alpha = 1.0/count_data.mean() #count_data is the variable that holds txtc
lambda_1 = pm.Exponential("lambda_1", alpha)
lambda_2 = pm.Exponential("lambda_2", alpha)
tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data)
and keep getting this error:
RuntimeError: module compiled against API version 9 but this version of numpy is 6
Traceback (most recent call last):
File "bayestest.py", line 1, in <module>
import pymc as pm
File "/Library/Python/2.7/site-packages/pymc-2.3-py2.7-macosx-10.8-intel.egg/pymc/__init__.py", line 29, in <module>
from .CommonDeterministics import *
File "/Library/Python/2.7/site-packages/pymc-2.3-py2.7-macosx-10.8- intel.egg/pymc/CommonDeterministics.py", line 21, in <module>
from .utils import safe_len, stukel_logit, stukel_invlogit, logit, invlogit, value, find_element
File "/Library/Python/2.7/site-packages/pymc-2.3-py2.7-macosx-10.8-intel.egg/pymc/utils.py", line 14, in from . import flib
ImportError: numpy.core.multiarray failed to import
Is something wrong with my library installation versions?
If you are on OS X, an easy way to ensure that your Python scientific packages are all compatible is to simply install my Scipy Superpack, or if you don't mind having a second Python installation on your system, to install Anaconda.
I think the OP should accept the answer form Chris Fonnesbeck above.
The PyMC installation was trying to find a numpy installation and came across the version from of numpy that shipped with OS X, thus felt it was too outdated to use. It wasn't because that version of numpy was not good - in fact, it was tested with all other components of the system extensively before distribution, it is just that PyMC requires newer features.
In my personal opinion, the easiest way to go is to install Anaconda, and allow it to register in your system.
EDIT:
Learned the etiquette a bit here, realize I shouldn't add the answer but comment - however, i don't have the privilege yet.
Related
I am struggling to install and import python libraries into my programs. originally I was using pydev but I kept getting messages like:
Traceback (most recent call last): File "C:\Users\satur\eclipse-workspace\DMD experimental\Main.py", line 11, in <module> from matplotlib import pyplot as plot ModuleNotFoundError: No module named 'matplotlib'
I installed matplotlib using py -m pip install matplotlib which produced a few messages like this.
WARNING: The script f2py.exe is installed in 'C:\Users\satur\AppData\Local\Programs\Python\Python310\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The scripts fonttools.exe, pyftmerge.exe, pyftsubset.exe and ttx.exe are installed in 'C:\Users\satur\AppData \Local\Programs\Python\Python310\Scripts' which is not on PATH.
I was unsure what this meant so I tried running my program again and got the module not found error again.
being unable to resolve the issue I moved over to spyder because it came with many of the libraries I wanted thus avoiding the issue. however, as soon as I tried to import and install libraries not included with spyder I encountered the module not found error and a similar warning about the path. I added the paths mentioned in the warning to the PATH in spyder now when I run my code get this error message:
runfile('C:/Users/satur/.spyder-py3/proper orthogonal decomposition/dynamic mode decomposition experimental driver.py', wdir='C:/Users/satur/.spyder-py3/proper orthogonal decomposition')
Traceback (most recent call last):
File "C:\Users\satur\AppData\Local\Programs\Spyder\pkgs\spyder_kernels\py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "c:\users\satur\.spyder-py3\proper orthogonal decomposition\dynamic mode decomposition experimental driver.py", line 13, in <module>
import mat73
File "C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\mat73\__init__.py", line 11, in <module>
import h5py
File "C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\h5py\__init__.py", line 25, in <module>
from . import _errors
ImportError: cannot import name '_errors' from partially initialized module 'h5py' (most likely due to a circular import) (C:\Users\satur\AppData\Local\Programs\Python\Python310\Lib\site-packages\h5py\__init__.py)
I did some looking around and found this
https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#installing-packages-into-the-same-environment-as-spyder
I followed what instructions I understood
import sys; sys.executable
Out[50]: 'C:\\Users\\satur\\AppData\\Local\\Programs\\Spyder\\Python\\python.exe'
which is different from what I get when I run it in command prompt or in the pydev terminal both of which give me
C:\Users\satur\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe
when i go to C:\Users\satur\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\ I see: 3 versions of idel, 3 versions of pip, and 6 versions of python.
I am deeply confused. I want to install and import libraries into my python programs. I want to be able to run my programs in either (or for that matter any) ide. I seem to be hitting the very similar issues in both. every tutorial I have found online describes the steps to take to do this but not what they are or why I am doing them none of them seem to work and the more times I try to install things the more confused I get.
could someone please explain: how to install and import libraries into a python program. what python is doing when I install things and try to import them. and why both IDEs have similar but different errors.
When I try to use numpy, I get an error, which is below. I have 2 questions, how do I work with numpy, I used pip to install, and how do I understand the error messages. I am a newbie in python
import numpy as np
array_a = np.array([1, 2, 3, 4, 5])
print(array_a)
Error:
[Johnnys-MBP:~/Desktop/python] johnbarrett% /usr/local/bin/python3 /Users/johnbarrett/Desktop/python/data.py
<class 'complex'>
1.4
2
Traceback (most recent call last):
File "/Users/johnbarrett/Desktop/python/data.py", line 1, in <module>
import numpy as np
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/__init__.py", line 140, in <module>
from . import core
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/core/__init__.py", line 70, in <module>
from . import numerictypes as nt
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/core/numerictypes.py", line 566, in <module>
_register_types()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/core/numerictypes.py", line 561, in _register_types
numbers.Integral.register(integer)
AttributeError: module 'numbers' has no attribute 'Integral'
Do you have the NumPy module installed on your computer? You have to locate it online and install it.
https://scipy.org/install.html
I found a package of a bunch of different scientific modules in python and within that (after I installed it it was about 700mbs) was a number of python terminals and numpy was installed on them. I did not get it to work on my standard 3.7/3.8 IDE offical python distributions. Sorry if this doesn't help, hope it does!
edit I choose WinPy BTW I have an intel chipset too and have no issues
You can install any IDE like pycharm. It will be more convenient to work with python. If you already have pycharm, then you can install numpy in this way: file-> settings-> python interpreter-> '+' symbol on the top right of the screen-> now u can install any packages using the search box. Hope you will find this helpful :)
I have a numerical simulation program that works fine at the institute I'm in, there I have a Win10 box where I installed Python 3.7.3 64-bit. I am trying to run the same program in my laptop with Manjaro and Python 3.8.1 (It was also 3.7.3 at the time I installed it, but rolling release ¬¬). The problem is that in my laptop I am getting the following error when trying to import pyFFTW
Traceback (most recent call last):
File "/home/User/Documents/Program.py", line 22, in <module>
import pyfftw # Pythonic wrapper for FFTW
File "/usr/lib/python3.8/site-packages/pyfftw/__init__.py", line 43, in <module>
from . import interfaces
File "/usr/lib/python3.8/site-packages/pyfftw/interfaces/__init__.py", line 237, in <module>
from . import scipy_fftpack
File "/usr/lib/python3.8/site-packages/pyfftw/interfaces/scipy_fftpack.py", line 65, in <module>
from scipy.fftpack import (dct, idct, dst, idst, diff, tilbert, itilbert,
ImportError: cannot import name '_fftpack' from 'scipy.fftpack' (/usr/lib/python3.8/site-packages/scipy/fftpack/__init__.py)
Process finished with exit code 1
As far as I can tell the problem is arising from the libraries within the pyFFTW package itself, but I have no idea how to fix it. I tried uninstalling and reinstalling both pyFFTW (1.17.4) and scipy (1.4.1) with little success.
I thought that I could install another version on Python in my Manjaro box and simply "match" all the versions of the packages in the Win box, but I'm looking for a less nuclear solution.
Just for completeness sake, MWE:
$ python
>>> import pyfftw
This is fixed in master. A release should be made shortly. You can either wait for that or pull from github.
Edit: Release made that fixes this on Feb 3 2020.
python 3.7.3, rpy2 3.2.0, the following code:
from rpy2 import robjects
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".virtualenvs/flask3/lib/python3.7/site-packages/rpy2/robjects/__init__.py", line 14, in <module>
import rpy2.rinterface as rinterface
File ".virtualenvs/flask3/lib/python3.7/site-packages/rpy2/rinterface.py", line 6, in <module>
from rpy2.rinterface_lib import openrlib
File ".virtualenvs/flask3/lib/python3.7/site-packages/rpy2/rinterface_lib/openrlib.py", line 65, in <module>
_get_dataptr_fallback)
File ".virtualenvs/flask3/lib/python3.7/site-packages/rpy2/rinterface_lib/openrlib.py", line 50, in _get_symbol_or_fallback
res = getattr(rlib, symbol)
RuntimeError: found a situation in which we try to build a type recursively. This is known to occur e.g. in ``struct s { void(*callable)(struct s); }''. Please report if you get this error and really need support for your case.
What's going on? This looks like standard procedure for rypy2, and indeed how we used it under python 2.
Same issue applies for any kind of rpy2 import: import rpy2.robjects.tests etc.
I ran into the same problem and found the same issue #ejolly linked above. To get around it, I downgraded my cffi library from 1.13.0 to 1.12.3.
pip install cffi==1.12.3
Worked like a charm.
edit:cffi 1.13.1 is released. Just update it and all should work.
The issue appeared with cffi 1.13.0, but appears limited to the ABI mode.
rpy2 will try to use the API mode, but if it fails will silently fall back to the ABI mode. If your system can be configured to have a C compiler, the API mode should be installed. To force the use of the API mode, set the environment variable:
RPY2_CFFI_MODE=API
(see info box in the doc:
https://rpy2.github.io/doc/v3.2.x/html/overview.html#install-from-source)
In a round about way, I corrupted my scipy/numpy installation on my IntelX64/Windows 7/Python 2.7 computer. I did this by trying to play around with some neural network libraries (lasagne/theano).
To fix this, I completely removed/reinstalled python 2.7.9. After that, I went to http://www.lfd.uci.edu/~gohlke/pythonlibs/ to download and install numpy and scipy with commands:
pip install C:\Users\me\Documents\numpy-1.9.2+mkl-cp27-none-win_amd64.whl
This went well and succeeded. (I can import numpy from python)
pip install C:\Users\me\Documents\scipy-0.15.1-cp27-none-win_amd64.whl
This appeared to go well too. Except the error occurs in the python console:
>>> from scipy import stats
Gives:
Traceback (most recent call last):
File "<stdin>", line1, in <module>
File "C:\Python27\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Python27\lib\site-packages\scipy\stats\stats.py", line 184, in <module>
import scipy.special as special
File "C:\Python27\lib\site-packages\scipy\special\__init__.py", line 586, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
I read up on the DLLs required and ran the 'dependency walker' (http://www.dependencywalker.com/) on "c:\python27\lib\site-packages\scipy\special_UFUNCS.PYD" and it seems there are a few DLL files not found.
libifcoremd.dll
libiomp5md.dll
libmmd.dll
msvcr90.dll
dcomp.dll
ieshims.dll
and a 6 files that look like 'api-ms-win-....dll'
From my looking around, people have solved this by reinstalling numpy, then scipy. I have tried that and the same thing occurs.
Has anyone else run into this issue and solved it?
I fixed this by a complete removal of everything (python and packages) and then installing everything again.
Just reinstalling the offending packages did not work. Neither did system restore. I will not accept this answer, because removing/installing is a work around to the real problem. I just want to post this to help anyone else in this position.
Simply install 'NumPy-1.9+MKL' from this page, it should work fine.
Acknowledgement: Another post here :)