I found the following problem in executing my python function:
Traceback (most recent call last):
File "/home/ppd/myfunc.py", line 2, in <module>
from cythonUtilsPy.cythonUtils import *
ImportError: No module named cythonUtils
How to add this cythonUtils module to my path?
Based on the error message, it looks like cythonUtilsPy is already on your path and was found, but the submodule cythonUtilsPy.cythonUtils was not found. Unless you are importing the wrong cythonUtilsPy, there is no path manipulation you can do to fix this.
You need to track down why cythonUtils is not showing up as a submodule of cythonUtilsPy, if cythonUtils is a directory perhaps it is missing an __init__.py.
Related
I want to import the function write_dynamic_data located in utilities.py into the file trigger_utilities.py which is lower in the hierarchy, but this error is showing up. How can I do? I'm avoiding to use sys.path as I've read it's a bag practise. I'm using Python 3.8.9 and I thinks it isn't necessary anymore).
Project stucture:
utilities.py
[processing]
trigger_utilities.py
This is the console output:
matidellatorre#MacBook-Pro-de-Mati myCode % /usr/bin/python3 /Users/matidellatorre/Desktop/Development/myCode/processing/trigger_utilities.py
Traceback (most recent call last):
File `"/Users/matidellatorre/Desktop/Development/myCode/processing/trigger_utilities.py", line 7, in <module>`
from ..utilities import write_dynamic_data
ImportError: attempted relative import with no known parent package
Thanks in advance!
I am new to python and I cannot get my head around why I am facing with the error in title.
This is my project structure:
and this is what I have inside shipping.py module:
def calc_shipping():
print('Calculating shipping...')
so when I do -> from ecommerce.shipping import calc_shipping
and want to use calc_shipping()
I get error ->
Traceback (most recent call last):
File "/Users/burakhanaksoy/gitHub/Python/PythonStudy/bman/basics/modules/app.py", line 9, in <module>
from ecommerce.shipping import calc_shipping
ModuleNotFoundError: No module named 'ecommerce'
any help is appreciated.
best,
PS: I get the same error in PyCharm as well, in fact in PyCharm, it doesn't even auto-fill 'ecommerce' or 'ecommerce.shipping' as I type
from ecommerce.shipping import calc_shipping
On such scenarios always check following things:
if the module has init, in other words if its a python module
check if its accessible from parent dir, in this example basics.
The importing is as below:
from settings import Settings
And it gave a traceback.
Traceback (most recent call last):
File "c:\0Data\Desktop\Alien_invasion\Aliens.py", line 5, in <module>
from settings import Settings
ModuleNotFoundError: No module named 'settings'
I checked. It's the exact same. The book is Python crash course 2nd edition page 235.
There's a file you're missing that you need, from a quick Google search:
https://github.com/ehmatthes/pcc
Pull it from there ^ depends on what chapter you're on. Make sure you put it in your working directory.
The Python Standard Library does not have any module named settings. Most likely is a module created previously in the book or something installed with Pip
I got the below shown error. Can anyone please help me with a solution?
from common import anorm, getsize
Exception:
Traceback (most recent call last): File "<pyshell#10>", line 1, in <module>
from common import anorm, getsize
ImportError: cannot import name anorm
Sorry for necroposting, but for anyone who's stuck on this:
apparently, you're trying to run the opencv example somewhat like this one. You need to copy the common.py from the same directory as well and everything would be fine (no need to install common package which has nothing to do with this partucular problem).
The common module does not contain an importable item named anorm. Simple as that.
Some possible reasons why:
The common module was not installed correctly.
Misspelling of the name of the item to be imported.
A file named common.py exists in the current directory, which takes precedence over the real common module (wherever it is).
Circular imports (which don't appear to be the case here, given the error traceback).
I have the following code with few modules:
import Persistence.Image as img
import sys
def main():
print(sys.path)
original_image = img.Image.open_image()
if __name__ == "__main__":
main()
(I've created my own Image module)
And so I'm getting the following error claiming that the Persistence module does not exist:
Traceback (most recent call last):
File "/home/ulises/PycharmProjects/IntelligentPuzzle/Puzzle.py", line 1, in <module>
import Persistence.Image as img
ImportError: No module named Persistence.Image
I've been searching for this problem here but can't find anything that worked to solve this as the directory tree seems to be correct as you can see on this image:
I'm using ubuntu if it's any use.
Thanks and regards!
Persistence package does not exist in that source tree. There is a "Persistence" directory there, but it is not a package, because it does not contain a __init__.py file.
From the Python documentation:
The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later.
I don't believe that you are importing with proper syntax. You need to use from Persistance import Image as img. For example:
>>> import cmath.sqrt as c_sqrt
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cmath.sqrt
ImportError: No module named 'cmath.sqrt'; 'cmath' is not a package
>>> from cmath import sqrt as c_sqrt
>>> c_sqrt(-1)
1j