I am trying to import pylab and this is the code that I am writing.
import pylab
pylab.figure(1)
pylab.plot([1,2,3,4],[1,7,3,5])
pylab.show()
But I am getting the error that
File "E:\mitedx1\mitedx2\week1\pylab.py", line 2, in <module>
import pylab
File "E:\mitedx1\mitedx2\week1\pylab.py", line 4, in <module>
pylab.figure(1)
AttributeError: 'module' object has no attribute 'figure'
[Finished in 0.1s with exit code 1]
I tried to take help from the answers provided here
Anaconda: Unable to import pylab
but to no rescue. I have also checked the path with cmd, and it is showing the inclusion of C:\Anaconda and C:\Anaconda\Scripts there. What would be the solution to fix this problem?
You called your script pylab.py, rename it to something else.
E:\mitedx1\mitedx2\week1\pylab.py # <- you are importing from this not the pylab module
Make sure to delete the E:\mitedx1\mitedx2\week1\pylab.pyc file also.
Related
Note: I am just a beginner and doing this by myself, so if you can reply with basic descriptions, that could help more.
This is the code I wrote
from matplotlib import pyplot as plt
plt.plot([2, 1], [8, 2], 'ro')
However, I get this error. I had a code using same way to import and it used to work just fine. Now that code is not working either.
C:\Users\Tuna\PycharmProjects\start\venv\Scripts\python.exe C:/Users/Tuna/PycharmProjects/start/matplotlib.py
Traceback (most recent call last):
File "C:\Users\Tuna\PycharmProjects\start\matplotlib.py", line 1, in <module>
from matplotlib import pyplot as plt
File "C:\Users\Tuna\PycharmProjects\start\matplotlib.py", line 1, in <module>
from matplotlib import pyplot as plt
ImportError: cannot import name 'pyplot' from partially initialized module 'matplotlib' (most likely due to a circular import) (C:\Users\Tuna\PycharmProjects\start\matplotlib.py)
Process finished with exit code 1
To fix, you just need to rename your file to something that isn't matplotlib.py. Python thinks you are trying to import your own file matplotlib.py to use rather than the actual module and hence why you are getting a circular reference.
This should work fine if you have matplotlib installed, if not pycharm should prompt you to install it which should be the easiest way for you to use it in your project.
I'm trying to import autograd with the following line of code:
import autograd.numpy as np
However, I'm getting the following error when trying to run the script:
Traceback (most recent call last):
File "autograd.py", line 1, in <module>
import autograd.numpy as np
File "/home/hakon/Documents/FYS_STK4155/project2/code and plots/test/autograd.py", line 1, in <module>
import autograd.numpy as np
ModuleNotFoundError: No module named 'autograd.numpy'; 'autograd' is not a package
I've tried installing autograd through pip, pip3 and conda, but the error remains the same.
The problem is that your module (the one that you're running) has the same name that you're trying to import: autograd (.py). Try renaming your file and running it again.
aaossa's answer worked for me. If changing the module name that you are running doesn't work, please check if there is any other autograd(.py) that you created existing in your current directory. If so, you also need to change that file's name or delete it so that you can import "autograd".
I know other people went through this kind of problem but I still can't fix the problem. I just began to programming.
I use spyder IDE and get the following error when I run the code.
File "C:\Users\kaany\AppData\Roaming\Python\Python36\site-packages\matplotlib\path.py", line 25, in <module>
from . import _path, rcParams
ImportError: cannot import name '_path'
When I remove 'import matplotlib as plt' from my code everything goes fine.
I have numpy 1.13.3 and matplotlib 2.1.0
I'd appreciate if someone provided any solution to this.
Here is an issue some of you might have already encountered : I just installed matplotlib using :
pip install matplotlib
on my OS X El Capitan Version 10.11.1. It seems to me that the installation went well, and the packages are properly located in /usr/local/lib/python2.7/site-packages
I get no problem when I try to import matplotlib using :
import matplotlib
Now, when I try to import matplotlib.pyplot in a python script, using :
import matplotlib.pyplot as plt
the program starts hanging, and I have to interrupt it using Keyboard Ctrl + C.
Besides, when I only import matplotlib and try to run this piece of code :
import matplotlib
matplotlib.pyplot
I get this message in the terminal Session :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'pyplot'
Does anyone have a solution to fix this problem ?
My script was running well before. I had a series of crashes on some scripts where I had to fix some things. However, all of a sudden, I can't even run a script and my sublime text shell is displaying this error. I tried chasing down the files in my /Library/...python... files to see if any files got renamed or any part of the module scripts got renamed or something, but have yet to figure it out. What can I try. Or better question, what did I do all of a sudden to cause this, and how would I undo it? It was literally working fine less than an hour ago not to mention all day.
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/numerictypes.py", line 101, in <module>
import numbers
File "/Users/peter/Documents/Trading/Code/AlphaModelVer1/numbers.py", line 2, in <module>
import Quandl
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Quandl/__init__.py", line 11, in <module>
from .Quandl import (
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Quandl/Quandl.py", line 11, in <module>
import pandas as pd
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas/src/numpy.pxd", line 157, in init pandas.hashtable (pandas/hashtable.c:22984)
AttributeError: 'module' object has no attribute 'dtype'
EDIT:
Thanks to the comments! I had tried re-installing pandas, numpy, and Quandl. But it was all due to the fact I had renamed a helper script numbers.py, when it needed to draw that from within. Hint to all future users: Do not rename python scripts to existing module types.
I've had a similar error that was caused by installing a package while I had IPython running. Try reinstalling Pandas using pip (make sure all Python instances are closed) and maybe you'll have to reiinstall hashtable as well, I can't remember.
try to reinstall this Quandl library
File
"/Users/peter/Documents/Trading/Code/AlphaModelVer1/numbers.py", line
2, in
import Quandl
pip uninstall Quandl
pip install Quandl
This problem occurred with me in spite of not naming the script name to the existing module name. I tried the following and it worked.
Instead of "import Quandl", I did "from Quandl import Quandl" and it worked for me!