I'm getting a module import error.
My main file is /home/mininet/pythonscripts/import.py:
and my module file is /home/mininet/test/hello.py:
The error I'm getting is:
File "import.py", line 7, in <module> from test.hello import sqr,print_func
ImportError: No module named hello
i also added the __init__.py file in the module search path..please help!!
In order to import /home/mininet/test/hello.py as test.hello, you have to fulfill two requirements:
/home/mininet/test/__init__.py must exist to mark test as a package.
/home/mininet must be on sys.path so that Python finds test/hello.py when looking for test.hello.
Note that having /home/mininet/test on sys.path lets you import hello, but not import test.hello.
Related
When I try import fuzzymatcher I get the error:
ImportError: cannot import name 'ratio' from 'Levenshtein' (unknown location)
Add the line #include <Python.h> to first line of the file _levenshtein.c inside of the Levenshtein folder.
Then in fuzzywuzzy folder, replace from .StringMatcher import StringMatcher as SequenceMatcher with from Levenshtein import *.
Using cmd on windows 10 to run Python 2.7.16. When I run a .py file which imports scipy.py it comes up with the error:
"File "C:\Python27\scipy.py", line 18, in
from .python import string_types
ValueError: Attempted relative import in non-package"
As string_types should already be included in python, I don't understand why this error is happening and cant seem to get passed it. Does anyone know how to fix this?
you tried,
>>> from . import MyModule #MyModule.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Attempted relative import in non-package
>>>
here . mean your current path
try,
from MyModule import *
now you can use string_types
or
import MyModule as m
m.string_types
I m using this line in my python code
from test.dtracedata import instances
in eclipse.
Python Version-2.7.15
Then it will show this error
importerror: no module named dtracedata
I am using Scipy.stats to perform distribution fits on my data. It works perfectly on my machine. But when I package my script with Python source folder, python27.dll and try to run it on another machine (where python is not installed and I do not want to also) by invoking my script like below
Path/to/Python.exe Path/to/script.py
I get the follwing error
Traceback (most recent call last):
File "test2.py", line 2, in <module>
import scipy.stats
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\stats\__init__.py
", line 344, in <module>
from .stats import *
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\stats\stats.py",
line 173, in <module>
import scipy.special as special
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\special\__init__.
py", line 636, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
My script is
import sys
import scipy.stats
import numpy
dataarray= [2.45, 3.67, 1.90, 2.56, 1.78, 2.67]
desc = scipy.stats.describe(dataarray)
print desc
This occurs only on Scipy import and scipy operations, all other imports and operations work fine. My purpose is to run this script in different machines without having to actually install python
I pip install requests module and bs4 module. In C drive i can see the installed modules:
and this is the sys.path of the added modules:
When i check all sys.path with:
import sys
for i in sys.path:
print i
UPTADE
i get this list:
C:\Python27new\Lib\site-packages
C:\Program Files (x86)\ArcGIS\Desktop10.3\bin
C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy
C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcToolBox\Scripts
But when i try to import requests and bs4 modules i get an error:
>>> import requests
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import requests
ImportError: No module named requests
and the same for bs4 module:
ImportError: No module named bs4
If the picture is a listing of C:\Python27new\Lib\site-packages then you want that in your path, not C:\Python27new\Lib\site-packages\requests.