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!
Related
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
I want to run nupichelloworld (https://github.com/lonesword/nupichelloworld) within pycharm but can't figure out how to force it to see nupic libraries. All sources -- nupic.core, nupic.sources, nupichelloworld etc are located on the same level (/home) (I am using the NUPIC-03-11-2014 image which I took from
https://mega.co.nz).
When I try to run it in console, that's all right, but pycharm tells following:
/usr/bin/python2.7 /home/nupic/nupichelloworld/helloworld.py
Traceback (most recent call last):
File "/home/nupic/nupichelloworld/helloworld.py", line 22, in <module>
import nupic
ImportError: No module named nupic
there is the such imports in the file:
from nupic.research.spatial_pooler import SpatialPooler as SP
import numpy as np
How to solve it? Thanx!
You probably need to configure the project's interpreter paths to include your package.
I am trying to running the Sahana Eden software from terminal, but I keep getting an import error.
Traceback (most recent call last):
File "web2py.py", line 18, in (module)
import gluon.weidget
File "C:\Eden\web2py\gluon\__init__.py", line 15, in (module)
ImportError: No module named 'globals'
The globals module is right in the file where it is supposed to be. Below init
So I went into init and I removed the import to see what would happend.
#from globals import current
from html import *
from validators import *
The next local import, html, works fine, but then the next local import, "validators"(which is also right where it should be) gives me an import error as well.
Running python -V should tell you which version of Python you're running. --version is also an option.
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.
I'm trying to use the twisted.mail package in Python:
root#beagleboard:~/twisted# ls /usr/lib/python2.6/site-packages/twisted/mail/
__init__.py imap4.pyo pop3client.py smtp.py
__init__.pyo mail.py pop3client.pyo smtp.pyo
_version.py mail.pyo protocols.py tap.py
_version.pyo maildir.py protocols.pyo tap.pyo
alias.py maildir.pyo relay.py test
alias.pyo pb.py relay.pyo topfiles
bounce.py pb.pyo relaymanager.py
bounce.pyo pop3.py relaymanager.pyo
imap4.py pop3.pyo scripts
I have twisted.mail installed, and within it is a module called imap4. twisted/mail contains the magic init.py file which makes it a python module.
so i should be able to import from it:
root#beagleboard:~/twisted# python
>>> from twisted.mail import imap4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named twisted.mail
As you can see, I'm doing this on a Beagleboard running Angstrom, but that shouldn't matter, should it? However, I can do exactly the same thing on my Ubuntu 11.10 and it imports fine.
I have verified that I do not have a twisted.py module in my current directory.
What silly mistake am I making?
You're in the package that you're attempting to import. Go up one level first.