using numpy in python - python

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 :)

Related

I cannot import libraries into python despite repeatedly installing them

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.

How to solve import CNTK library?

I have problem with linking CNTK library with Anaconda.
My PYTHONPATH: c:\repos\cntk\bindings\python;%PYTHONPATH%
My CNTK_PY_35: C:\local\Anaconda3-4.1.1-Windows-x86_64\envs\cntk-py35
And I have error:
Traceback (most recent call last):
File "C:/Users/szymo/PycharmProjects/ImageClassification/Main.py", line 1, in <module>
import cntk
File "c:\repos\cntk\bindings\python\cntk\__init__.py", line 11, in <module>
from .core import *
File "c:\repos\cntk\bindings\python\cntk\core.py", line 10, in <module>
from . import cntk_py
ImportError: cannot import name 'cntk_py'
Anyone knows how to solve this problem?
Best
As Nikos points, this is very likely due to mixing up of binary installation with the toolkit being built from the sources.
Please try to add something like --with-py36-path=/opt/anaconda/envs/cntk-py36 to your ./configure command options before building CNTK. Please note that you may need to modify the path and Python version according to your setting. The above option is for Arch Linux with Python 3.6 (Anaconda).

Installing Scipy Error in Windows 7

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 :)

d3py installation error - no module named pandas_figure

I have problems installing d3py.
easy_install from https://github.com/mikedewar/d3py/tarball/master says it's all ok, cloning the repo and setup.py'ing say it's all ok as well, Pandas an Numpy works great (I also use Networkxs working good as well), bu when I try to import d3py come this Error:
Traceback (most recent call last):
File "C:\Documents and Settings\whoauser\Desktop\python\sofia\sofia.py", line 2, in <module>
import d3py
File "C:\Python34\lib\site-packages\d3py-0.2.3-py3.4.egg\d3py\__init__.py", line 1, in <module>
ImportError: No module named 'pandas_figure'
Is this a bug in the installation script? Where I can find a working egg?
Do anyone had the same problem?
Thanks
I think you need to install the pandas module for python. Have you done that?

Trouble with pymc library

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.

Categories