PyCharm- AttributeError: module 'numpy' has no attribute 'arange' - python

I've just installed a NumPy in my computer and everything in Python consol is OK- https://i.stack.imgur.com/DFC4O.png
but in every interpreter i have the same problem:
https://i.stack.imgur.com/ANxG2.png
Thanks for help!

You called your program file numpy.py so the file is trying to import itself rather than the real numpy module. Call your file something like numpy_test.py instead.

Be sure you use the correct Python path.
If other attributes works well?
you should check this link first Why does PyCharm give unresolved reference errors on some Numpy imports?

Related

I not able to import pygame module in linux

[![this is the image for reference
I am not able to use the init function.
please solve this issue.
]1]1
You named your script pygame.py, that is a very bad idea because it shadows the real pygame module, change the name of your script and it should work fine.

Using a function from a built-in module in your own module - Python

I'm new with Python and new on Stackoverflow, so please let me know if this question should be posted somewhere else or you need any other info :). But I hope someone can help me out with what seems to be a rather simple mistake...
I'm working with Python in Jupyter Notebook and am trying to create my own module with some selfmade functions/loops that I often use. However, when I try to some of the functions from my module, I get an error related to the import of the built-in module that is used in my own module.
The way I created my own module was by:
creating different blocks of code in a notebook and downloading it
as 'Functions.py' file.
saving this Functions.py file in the folder that i'm currently working in (with another notebook file)
in my current notebook file (where i'm doing my analysis), I import my module with 'import Functions'.
So far, the import of my own module seems to work. However, some of my self-made functions use functions from built-in modules. E.g. my plot_lines() function uses math.ceil() somewhere in the code. Therefore, I imported 'math' in my analysis notebook as well. But when I try to run the function plot_lines() in my notebook, I get the error "NameError: name 'math' is not defined".
I tried to solve this error by adding the code 'import math' to the function in my module as well, but this did not resolve the issue.
So my question is: how can I use functions from built-in Python modules in my own modules?
Thanks so much in advance for any help!
If anyone encounters the same issue:
add 'import math' to your own module.
Make sure that you actually reload your adjusted module, e.g. by restarting your kernell!

matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'

I am a newbie to python and i am trying to learn online. I tried importing matplotlib on python 3.6 but i keep getting this error:
problem in matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'.
I am using Anaconda. and i have installed the matplotlib library too. I have no idea what is going on. Please help.
As you told us in your comment, your file is named numbers.py. This file is probably the problem, as it hides the numbers.py file used by matplotlib. Your numbers.py file does not provide the Integral attribute, thus the error message.
Solution: Rename your file.

NameError: name 'reload' is not defined

I'm using python 3.2.2. When I write a simple program, I meet the problem.
>>> reload(recommendations)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
reload(recommendations)
NameError: name 'reload' is not defined
How should I do it?
You probably wanted importlib.reload().
from importlib import reload
In Python 2.x, this was a builtin, but in 3.x, it's in the importlib module.
Note that using reload() outside of the interpreter is generally unnecessary, what were you trying to do here?
An update to #Gareth Latty's answer. imp was depreciated in Python 3.4. Now you want importlib.reload().
from importlib import reload
Try importlib.reload.
Reload a previously imported module. The argument must be a module object, so it must have been successfully imported before. This is useful if you have edited the module source file using an external editor and want to try out the new version without leaving the Python interpreter.
from importlib import reload
reload(module_name)
As others have said, you need either importlib.reload(module) or at some earlier point you need to from importlib import reload. But you can hide the from importlib import reload in an initialization file. Make sure that PYTHONSTARTUP is defined in your shell. For example,
export PYTHONSTARTUP=$HOME/python/startup.py
might a reasonable line to add to your ~/.bash_profile, if your shell is bash, and depending on where you store your python files. (If you’re following these instructions, start a new terminal window at this point so that the line is executed.) Then you can put the line
from importlib import reload
in ~/python/startup.py and it will happen automatically. (Again, if you’re following along, start a new python session at this point.) This might look a bit complex just to solve this one problem, but it’s a thing you only have to do once, and then for every similar problem along the lines of “I wish python would always do this”, once you find the solution you can put it in ~/python/startup.py and forget about it.

Why this python program is not working? AttributeError: 'module' object has no attribute

I wrote a very simple python program.
#!/usr/bin/env python
import random
x = random.uniform(-1, 1)
print str(x)
I run this from command prompt.
python random.py
It returned with error:
Traceback (most recent call last):
File "random.py", line 2, in <module>
import random
File "D:\python practise\random.py", line 3, in <module>
x = random.uniform(-1, 1)
AttributeError: 'module' object has no attribute 'uniform'
It is a very simple program, I can't understand what mistake I did in this.
(operating system: Windows 7; python version: 2.7)
Don't name your file random.py, it is importing itself and looking for uniform in it.
It's a bit of a quirk with how Python imports things, it looks in the local directory first and then starts searching the PYTHONPATH. Basically, be careful naming any of your .py files the same as one of the standard library modules.
Don't name your program as an Library.
And just as a Tip: You don't need an String storing something and printing it out just after generating it.
#!/usr/bin/env python
import random
print(random.uniform(-1, 1))
This will work fine too ;)
Your problem is that you named your test program "random.py". The current working directory is on the module search path before anything else, so when you say "import random", it imports your own test program rather than the standard library random.
Rename your test program -- or just take the .py suffix off -- and it should work.
The solution to your problem is renaming your file (random.py) to something other than Python built-ins, standard libraries, reserved keywords etc.
However I strongly recommend you take Python Tutorial, before trying any other tutorial or book. You especially need to learn more about Python scopes and namespaces.

Categories

Resources