Load Modules in Wing IDE - python

I am new to Python and am having trouble loading numpy in Wing IDE. I can load the module and use it fine in the command line but not in Wing IDE. Below is what I am seeing:
code:
import numpy as np
a=np.arange(15)
result:
[evaluate numpy.py]
Traceback (most recent call last):
File "C:\Users[my name]\Documents\Python\practice\numpy.py", line 2, in 0
builtins.NameError: name 'arange' is not defined
I have also tried to use the help() command:
code:
help(np)
result:
Help on module numpy:
NAME
numpy
FILE
c:\users[my name]\documents\python\practice\numpy.py

It is probably due to your code being in a file named numpy.py If you do this then 'import numpy' may import your module and not numpy. This depends on what's on the Python Path and possibly current directory, which probably explains why it works outside of Wing.

Related

trouble importing autograd in python script

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".

RaspberryPi: ImportError: No module named cv2 in Geany

I installed opencv in RaspberryPi (using this link)and import in termial and python3 (idle). It shows no error in these two as shown in below images.
But, when I tried to run import cv2 in Geany, it shows error given below:
Traceback (most recent call last):
File "import.py", line 1, in <module>
import cv2
ImportError: No module named cv2
How I can solve this problem?
I solved this problem by changing python to python3 in Geany.
For this, Go to Build->Set Build Commands in Geany menu. In Set Build Commandswindow, under Python commands label in compile line python m py_compile will be there. Similarly, under Executive commands label in executive line python "%f" will be there. I changed python m py_compile into python3 m py_compile and python "%f" into python3 "%f" (as shown in images 1 and 2) and above-mentioned problem get solved.
Image 1.
Image2.
Thanks.

Error on calling a function from another file on python

I'm getting an error on importing a function from another file in python.
This is my file structure
In checkSpellings.py there's a function defined as spellchecker(tokenized_text) . And I'm trying to use it by importing it on main.py by following code
from checkSpellings import spellChecker
But it gives me an warning (red underline on top of both of checkSpellings(file name) and spellChecker(function name) in import code). This previously happened and I though this is purely an issue with intellisense . Because last time same thing happened (gave me the warning), but the code worked fine.
But now when I run the main.py it gives me an error saying
Traceback (most recent call last):
File "/home/pankaja/Documents/PycharmProjects/BookDigitizer/OCR_Correction/main.py", line 1, in <module>
from checkSpellings import spellChecker
ImportError: cannot import name 'spellChecker
How can I fix this ? What have I done wrong ?
IMPORTANT : Here I'm using python3.6 interpreter on an anaconda virtual environment. Might it be an issue ?
The function is spellchecker but you tried to import spellChecker.

Importing matplotlib.pyplot in atom editor

I am using pyzo to run my python scripts. However I felt the need to switch over to the Atom code editor. I can run my python scripts without any problem.
At one point I need to use the library matplotlib. In pyzo I would do:
import matplotlib.pyplot as plt
But it doesn't work in Atom
Error message:
Traceback (most recent call last):
File "C:\Users\ivanl\Desktop\python trade\matplotlib.py", line 1, in
import matplotlib.pyplot as plt
File "C:\Users\ivanl\Desktop\python trade\matplotlib.py", line 1, in
import matplotlib.pyplot as plt
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
Where should I look for installing matplotlib? Why is it working on pyzo and not on atom?
From The Module Search Path.
When a module named spam is imported, the interpreter first searches
for a built-in module with that name. If not found, it then searches
for a file named spam.py in a list of directories given by the
variable sys.path. sys.path is initialized from these locations:
the directory containing the input script (or the current directory).
PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
the installation-dependent default.
Which means you should avoid naming your modules with the same name as standard-library or built-in module names.
So you should rename your script file instead of matplotlib.py.
I faced a error like below while trying to import Matplotlib from atom:
Traceback (most recent call last):
File "lanes.py", line 3, in
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'.
All I did is go to my C:\Users*user_name*.atom directory in command prompt and type pip3 install matplotlib. Now it works fine.
So in command prompt you need to give something like below:
C:\Users\*user_name*\.atom>pip3 install matplotlib.
Hope it works.

ImportError with different python installations.

I am getting below ImportError while running a python file.
ImportError: No module named osgeo.gdal_array
!/usr/bin/env python
from osgeo.gdal_array import BandReadAsArray
However, if i try to import same from command line, it runs fine.
$ which python
/home/hduser/anaconda2/bin/python
$ python
>>> from osgeo.gdal_array import BandReadAsArray
>>>
Also, please see the below where i am getting the same ImportError.
$ /usr/local/bin/python2.7
>>> from osgeo.gdal_array import BandReadAsArray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named osgeo.gdal_array
I figured out that there is something going on between different versions of python. But, i do not want to change the original source code.
How do i make my program run without changing anything within the code of calling python installed in anaconda explicitly?

Categories