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
You have (at least) 2 Python installations, one managed by Anaconda, the other what appears to be an official Python.org Mac build installed system-wide. The pip command on the command-line is the one tied to the Python.org Mac build.
pip is a script that is tied to a specific Python installation, and there can be multiple versions of the script installed in different locations, and is usually also installed with pipX and pipX.Y to match the X.Y version indicator of the Python version it is tied to. For Python 3.6, that means the same script would also be available as pip3 and pip3.6. (This also means that pip can be connected to Python 2 or Python 3, depending on your exact OS setup. It is not a given that pip, without a version number, installs into Python 2.x as some answers may claim).
Note that when you run a command without a path in your shell, (such as pip as opposed to /usr/bin/pip), you are asking your shell to find the command for you in a number of locations, listed in the PATH environment variable. The first location in the PATH list with that command is then fixed. which -a <command> would tell you all possible PATH-registered locations that the command can be found in. You can always use the full path to a command to bypass the PATH search path.
You can always verify what Python version the pip command is connected to with:
pip -V
which will output the version of pip and the location it is installed with. It'll print something like
pip pipX.pipY path/to/pythonX.Y/site-packages/pip (python X.Y)
where pipX.pipY is the pip version number and path/to/pythonX.Y tells you what Python installation this is for.
You can try to match this with the Python version by running
python -m site
which outputs the Python module search path for that Python version. Python can be run with python, pythonX and pythonX.Y too, and is subject to the same PATH search.
Note the -m switch there, that instructs Python to find a module in it's module search path and execute it as a script. Loads of modules support being run that way, including pip. This is important as that helps avoid having to search for a better pip command if you already can start the right Python version.
You have several good options here:
Since you are using Anaconda, you could look for a conda package for the same project. There is such a package for
wfdb. Install it withconda install wfdbAnaconda aims to give you a wider software management experience that includes a broader set of software options than just the Python PyPI ecosystem, and conda packages usually manage more things than just the Python package.
Conda packages are usually maintained by a different set of developers from the package itself, so there may be a newer version available on PyPI (requiring
pip install) than there is on Conda.This is not an option for all Python packages, if there is no
condapackage you have to usepip. See Installing non-conda packages.you can use the
condacommand to create a conda environment. Once you have an environment created, you can activate it withsource activate <name_of_cenv>to alter your
PATHsettings. With the envirnoment 'active' the first directory listed on yourPATHis the one for the conda environment and thepipcommand will be the one tied to that environment.Note that a conda environment gives you an isolated environment for a specific project, keeping the library installation separate from the rest of your Python packages in the central
site-packageslocation. If you want to install a package for all of your Anaconda Python projects, don't use a conda environment.Use the Anaconda Python binary to run
pipas a module; when you can run/path/to/pythonorpythoncommandto open the right Python version, you can use that same path to run/path/to/python -m pip ...instead ofpip ...to be absolutely certain you are installing into the correct Python version.Look for a better
pipcommand, withwhich -a piporwhich -a pip3.6, etc. But if you already know the Python binary, look in the samebinlocation forpip. If you haveanaconda/bin/python, then there probably is aanaconda/bin/piptoo.
which python
gives the you the PATH to python
and then /path/to/python -m pip install thepackagetobeinstalled
Many thanks @MartijnPieters