Am trying to run a python script that i downloaded from the internet
import os, subprocess, sys, socket, time, struct, random, xml.sax, getopt
import shutil
import Output
import numpy as np
...
I get the error
Traceback (most recent call last):
File "downtown.py", line 20, in <module>
import Output
ImportError: No module named Output
Am totally new to python , and I want to know whether the missing import is python's or a user library
As a first hint, observe the missing module Output starts with a capital O, which fails to follow convention of using lowercase-only for module names. Therefore Output is most certainly a user library. Alternatively, Output might be a class that would correctly need to be imported via from somelib import Output.
It is not a standard module - it looks like a user module that you should also download from wherever you got the original script.
Related
Guys I'm new in Python and I'm trying to understand modules.I have a folder in desktop and there are 2 module in that folder. One of them is pr.py ,it's takes a array and displays it.And other one is fillArray.py.Now I want to add these 2 friend into interpreter but when I used in interpreter import pr.py or import fillArray it's giving to me this error
>>> import pr
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pr
ImportError: No module named pr
Then if I clicked f5(run) in pr.py module ,write again in interpreter import pr it works.That's ok.But trying to run fillArray.py module same steps, it's restart interpreter and it works butpr.py module is removing.How can I handle this?By the way this can be unnecessary but I'm using python2.7.
Edit:I wrote print.py sorry it should be pr.py
If you have both the modules in the same folder, you can use . which specifies current directory as follows:
from .pr import *
This statement will import all functions of print.py which is in the current directory
If you want specific things to be imported, just specify using their names
from .pr import myfunc1, myfunc2, myclass1, myclass2
If you wish to import the whole module, use:
from . import pr
Hope this helps :)
When I import a module, it works on linux, but fails in windows, with the error:
<Directory>\src>main.py
Traceback (most recent call last):
File "<Directory>\src\main.py", line 12, in <module>
from parser.parser import Parser
ImportError: No module named parser
On windows it seems that it cannot find the file parser.py (created by me). I don't understand why because it found all the other modules.
[folder:
- main.py
- parser/__init__.py
- parser/parser.py]
The problem is with the package name parser . By importing from parser you import the parser module from the standard library that has no parser.parser submodule. See parser.
I encountered the same problem, and got it solved.
Here's how.
Check your sys.path (import it first) to see whether your coding-file's directory is included in it. If not, append it.
That's my code:
import sys
import os
sys.path[0]=os.path.dirname(os.path.realpath(__file__))
Tell me if it doesn't work.
BTW, I'm Chinese so ignore any grammatical errors. I think you understand what I mean.
when i am importing some modules from python shell, import work fine:
for example: (link for propy module https://code.google.com/p/protpy/downloads/list)
>>> import propy
>>>
but when i write script with python Default IDLE or with other IDE and save it to as .py script , import statements not work and generate error like this
python fragment_generator.py
>>>
Traceback (most recent call last):
File "J:\acetylome scripts\New folder\fragment_generator.py", line 1, in <module>
import propy
ImportError: No module named propy
>>>
please solve it
thanks in advance:
When you run the shell from the same directory the files are in the import will work. You are probably working from another directory when the import fails.
you can add a directory to the python path like this.
befor your import:
import sys
sys.path.append('/path/to/your/folder')
import propy
good luck.
I need to make a portable app to put on a device and I want to put only the modules needed so there will not be all the standard modules so I need to see what my app needs, but if that module misses some imports I cannot see that, because it gives an error without being explicit what fails in that module:
Traceback (most recent call last):
File "./packaging.py", line 30, in <module>
import simplejson
ImportError: No module named simplejson
Is there a way to see what import exactly fails in that module?
The error means, that the import import simplejson fails because there is “[n]o module named simplejson”. The solution is to simply install said module.
It could be that the string /usr/lib/python2.7/dist-packages is not in your sys.path folder list so it's not being searched when attempts are made to import modules or packages.
you can catch the exceptions, to know what went wrong and handle them appropriately:
try:
import simplejson
except ImportError:
print "simplejson module not found"
#or do something else here, may be install that module
I'm a Python newbie, so bear with me :)
I created a file called test.py with the contents as follows:
test.py
import sys
print sys.platform
print 2 ** 100
I then ran import test.py file in the interpreter to follow an example in my book.
When I do this, I get the output with the import error on the end.
win32
1267650600228229401496703205376
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named py
Why do I get this error and how do I fix it? Thanks!
Instead of:
import test.py
simply write:
import test
This assumes test.py is in the same directory as the file that imports it.
This strange-looking error is a result of how Python imports modules.
Python sees:
import test.py
Python thinks (simplified a bit):
import module test.
search for a test.py in the module search paths
execute test.py (where you get your output)
import 'test' as name into current namespace
import test.py
search for file test/py.py
throw ImportError (no module named 'py') found.
Because python allows dotted module names, it just thinks you have a submodule named py within the test module, and tried to find that. It has no idea you're attempting to import a file.
You don't specify the extension when importing. Just do:
import test
As others have mentioned, you don't need to put the file extension in your import statement. Recommended reading is the Modules section of the Python Tutorial.
For a little more background into the error, the interpreter thinks you're trying to import a module named py from inside the test package, since the dot indicates encapsulation. Because no such module exists (and test isn't even a package!), it raises that error.
As indicated in the more in-depth documentation on the import statement it still executes all the statements in the test module before attempting to import the py module, which is why you get the values printed out.