The issue was in the naming of my file.
I hastily named my file emailage.py and then tried to import from emailage.client.
I'm assuming that Python looked in my current directory and matched the names of the file I was working on before checking the installed third party libraries.
After renaming my file everything seems ok.
For others who run into similar problems -- beware of conflicting naming. Sometimes the simplest things trip you up the longest.
Answer from Aaron Taveras on Stack OverflowThe issue was in the naming of my file.
I hastily named my file emailage.py and then tried to import from emailage.client.
I'm assuming that Python looked in my current directory and matched the names of the file I was working on before checking the installed third party libraries.
After renaming my file everything seems ok.
For others who run into similar problems -- beware of conflicting naming. Sometimes the simplest things trip you up the longest.
I ran into something similar and the answer from OP about namespace collision is what finally clued me in.
I was using the same name for both a sub-package (directory) and a module (file) within it.
For example I had this:
/opt/mylib/myapi
/opt/mylib/myapi/__init__.py
/opt/mylib/myapi/myapi_creds.py # gitignored file for user/pass
/opt/mylib/myapi/myapi.py # base module, load creds and connect
/opt/mylib/myapi/myapi_dostuff.py # call myapi.py and do work
The script 'myapi.py' imports credentials from myapi_creds.py via this statement:
from myapi.myapi_creds import my_user, my_pass
Testing the module 'myapi.py' resulted in this error:
$ ./myapi.py
Traceback (most recent call last):
File "./myapi.py", line 12, in <module>
from myapi.myapi_creds import my_user, my_pass
File "/opt/mylib/myapi/myapi.py", line 12, in <module>
from myapi.myapi_creds import my_user, my_pass
ModuleNotFoundError: No module named 'myapi.myapi_creds'; 'myapi' is not a package
The solution was to rename myapi.py to myapi_base.py so it's name does not collide with the sub-package name.
Rename cts_sap_polaris.py to something else.
This name conflicts with the package name (which has the same name).
(credit goes to @jedwards on his comment)
From what i understand, python only searches the current directory and sys.path. So you can add to the python path at run time. A similar question has been answered here
I would suggest you to try this ..
# scripts/cts_sap_polaris.py
# Add additional path to current sys path
import sys
sys.path.insert(0,'/path/to/cts_sap_polaris/lib')
import cli_check
Let me know if it works.
In my python script I wrote:
import package.module
package.module.b()
for some reason it cant find the package and also calls it a module in the error
ModuleNotFoundError: No module named 'package'
i checked the spelling and the names of the module and the package
if you explain this it would me a lot thanks!
I'm working on a program that lets the user do mad libs, and I'm importing the prompts from a file in a subdirectory (prompts being "enter a noun", for example). The file tree looks something like this:
Mad Libs
|
libs
/\
lib 1 lib2
/\
prompts.py text.txtif I import from a test file in the "Mad Libs" directory, it imports just fine. But if I import from the main program, I get this error:
ModuleNotFoundError: No module named 'libs.lib 1.prompts.py'; 'libs.lib 1.prompts' is not a package
I'm using the importlib module for imports, since they're based on user-entered strings.
Any ideas what's going on here?
OK, I had solved this problem. In the directory util/__pycache__
There was a file par.cpython-35.py which had the same name with the directory package. This caused a confusion. After it been deleted , The problem solved.
The module in your code is called "rec-par", but when trying to import it you refer to "rec.par".
the dpkg error is a-bit misleading, what is missing isn't python but python-dev. Install python-dev with all it's dependencies.
I would suggest this code for dependency Problems
sudo apt-get install -f
This may solve Your problem if the dependent .deb files are in the Linux repository