I'm trying to import these libraries in python using this code:
import matplotlib as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
I get this error when I start debugging
Message=[WinError 193] %1 is not a valid Win32 application
Source=C:\Users\basse\source\repos\PythonApplication1\PythonApplication1\PythonApplication1.py
StackTrace:
File "C:\Users\basse\source\repos\PythonApplication1\PythonApplication1\PythonApplication1.py", line 2, in <module> (Current frame)
import matplotlib as plt
These are the commands that I used in Visual Studio's terminal to install the libaries:
pip install matplotlib
pip install pandas
pip install numpy
pip install sklearn
pip install pandas-datareader
pip install beautifulsoup4
What should I do to solve this problem? Please consider that I'm kind of a beginner so make your answer detailed. Thanks!
Edit: I always get the same error with the 4 lines of code. For example, if the first line is import pandas as pd, I'll also get the same error.
Related
I am trying to use the pandas data reader library.
I initially tried import pandas.io.data but this threw up an import error, stating I should be using
from pandas_datareader import data, wb
instead. Upon trying this I was greeted with
ImportError: No module named pandas_datareader
I have had a look around and have tried...
"pip install pandas_datareader"
"pip install python_datareader"
"pip install pandas-datareader"
Any help would be greatly appreciated
run this command pip install pandas-datareader and for more info documentation is here
I am new to python, and trying to run this example in Jupyter notebook. Whenever I run following
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.api import SimpleExpSmoothing
It gives me following error
ImportError Traceback (most recent call last)
<ipython-input-5-a15788c08ca7> in <module>()
3 import pandas as pd
4 import matplotlib.pyplot as plt
----> 5 from statsmodels.tsa.api import SimpleExpSmoothing
ImportError: cannot import name 'SimpleExpSmoothing'
Although, I have installed statsmodels (0.8.0) by
pip install statsmodels
like other packages (numpy, pandas etc.). I checked on git, api file contains this method but my api file (obtained through pip) doesn't have this method. Maybe I am not getting the git version (seems latest one) through pip? I am working in windows and I also tried on mac OSX, and result is same. I tried to do a copy/paste attempt for missing files/code in files from git (not a good way) but it doesn't help. I would appreciate your suggestions here.
EDIT
So the solution for Jupyter (thanks to #user333700) is to install master branch directly from git by
pip install git+https://github.com/statsmodels/statsmodels.git
I am extending my question for PyCharm, how can I add a git package within PyCharm? This link does not help.
For future reference another solution which worked for me is to pip install the latest version directly:
pip install statsmodels==0.9.0rc1
I'm working in Ubuntu as Virtual-Box guest on top of Windows machine (as host), and I am attempting to run my python script from the terminal. I had difficulty installing matplotlib using pip install. I managed to install it using
sudo apt-get install python-matplotlib
However, I am unable to bring up an image I have created in my code:
import numpy as np
import matplotlib.pyplot as plt
import random as random
from random import randrange
image = plt.imshow(mymatrix)
plt.show()
If I import matplotlib as:
import matplotlib as plt
I am recieving the following error on attempting to run the script:
AttributeError: 'module' object has no attribute 'imshow'
If I import matplotlib as:
import matplotlib.pyplot as plt
I recieve the following error:
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk
package
On attempting to install python-tk using 'pip install python-tk' this is what I'm getting:
~/ising $ pip install python-tk Collecting python-tk Could not find
a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk
I'm unsure if I have in fact incorrectly installed matplotlib from the beginning. I am aware pyplot is not automatically imported with matplotlib, could the same be true for installing it from the console? Seems like I have tried everything at this stage.
The problem appears to be that you do not have a graphical backend installed. The error you are getting about Python Tk is happening because normally Tk comes with any Python distribution, so you should have at least that. You can install any Python bindings for Tk, Pyqt4, Pyqt5, Wx, GTK, (possibly others) to get a working interactive graphical backend. Check the package repository for the actual package names to install.
Keep in mind that functions like imshow are part of the (sub)package matplotlib.pyplot, not matplotlib itself. import matplotlib as plt is simply wrong if you intend to do plt.imshow(...). The correct import is either from matplotlib import pyplot as plt or import matplotlib.pyplot as plt.
According to the documentation here try this
python -mpip install -U pip
python -mpip install -U matplotlib
I have installed the matplotlib in python,and when I import matplotlib,it works well.But when I import matplotlib.pyplot as plt,the command line prompt me that an importerror occurred.
ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /home/nju/anaconda2/envs/tensorflow/lib/python2.7/site-packages/matplotlib/_path.so)
How can I solve the problem?
Thanks very much
sudo apt install libgl1-mesa-glx
Above command is from the link below.
https://github.com/ContinuumIO/docker-images/issues/49
I used the following command to know the numpy version I am using
pip show numpy
output shown below
---
Name: numpy
Version: 1.8.2
Location: /usr/lib/python2.7/dist-packages
Requires:
However when I am running matplotlib, I got a error as
RuntimeError: module compiled against API version a but this version of numpy is 9
from matplotlib import pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/usr/local/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/usr/local/lib/python2.7/dist-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
I tried to upgrade numpy,
pip install numpy --upgrade
it shows to be installed successfully, but numpy still shows to be 1.8.2 and error continues to exist when running matplotlib.
I thought to uninstall numpy and reinstall it, the system gives the message saying
Not uninstalling numpy at /usr/lib/python2.7/dist-packages, owned by OS
how to solve it ?
any idea about
RuntimeError: module compiled against API version a but this version
of numpy is 9
How can I upgrade numpy? might be working for you. IN that case it was a path problem:
RuntimeError: module compiled against API version 9 but this version of numpy is 6
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
Solution:
Check the path
import numpy
print numpy.__path__
and manually delete it using rm
I also had the same problem until I came across this Issue on Pytorch github repository. This command worked perfectly for me:
pip install numpy -I
It is also mentioned there that pip install numpy --upgrade is not working(don't know why). You can check the above mentioned link.
I had a similar problem with numpy when running torch. I tried uninstalling numpy and installing it using -U but it didn't work. After some search, I found this link and it solved my problem. It says you should change your numpy version.
pip uninstall numpy
pip install numpy==1.19.3
The answer is probably simple.
Just add
import numpy.core.multiarray
before the
import cv2
statement.
It worked fine for me.
My problem is solved using the old version of numpy. The solution is to use numpy 1.19.3.
pip install numpy==1.19.3
Credit: https://stackoverflow.com/a/64730012
Installing the previous version of NumPy, 1.19.3 should fix this.
python -m pip install numpy==1.19.3