ModuleNotFoundError in Anaconda3 when installing package with pip - python-3.x

I'm running conda 4.4.8 on mac OS 10.11.16 and I'm trying to properly install a third-party package that I have as a tar.gz file. The package installation seems to work without any issue (having already tried to install, this in what I get when I run it again):
$: pip install ~/Downloads/pydelay-0.1.1.tar.gz
Processing ~/Downloads/pydelay-0.1.1.tar.gz
Requirement already satisfied (use --upgrade to upgrade): pydelay==0.1.1 from file://~/Downloads/pydelay-0.1.1.tar.gz in ~/anaconda3/lib/python3.6/site-packages
Building wheels for collected packages: pydelay
Running setup.py bdist_wheel for pydelay ... done
Stored in directory: ~/Library/Caches/pip/wheels/5d/b7/4e/3896677f80cccebfc2d300904aca54ebbd6b0885cb9440e13d
Successfully built pydelay
Then I do a check to make sure there aren't dependencies missing:
$: pip check pydelay
No broken requirements found.
However, when I run my piece of code that uses the package, I get the following error:
runfile('~/.../DDEin3+1D.py', wdir='~/...')
Traceback (most recent call last):
File "ipython-input-16-12e8207a0dca", line 1, in
runfile('~/.../DDEin3+1D.py', wdir='~/...')
File "~/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "~/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "~/.../DDEin3+1D.py", line 18, in
from pydelay import dde23
File "~/anaconda3/lib/python3.6/site-packages/pydelay/__init__.py", line 9, in
from _dde23 import dde23
ModuleNotFoundError: No module named '_dde23'
I don't think its a version problem, but because the pydelay package is from 2009 it very well could be.
Any help with getting the spyder editor (or command line python) to find this package would be greatly appreciated!
pythonanaconda3

Just in case anyone runs into something like this, I thought I would post the solution. In this instance, the __init__.py file was searching my default PATH for _dde23, which was actually located in the same directory as __init__.py. The solution was simply to change the import call in __init__.py to
from ._dde23 import dde23
This told the file to look within the same directory for the module. I found similar problems throughout the package, and with this small change solved them all. I'm not an expert, but it might have been something to do with pydelay being built with python2.x while I was running python3.x.
Of course, getting other parts of this module to work with depreciated dependencies is another matter ;)

Related

Pip can't find module pip._internal.utils

I did a fresh install of Python 3.8.3 for Windows 10. I can't get pip to work, it keeps complaining about module pip._internal.utils that can't be found.
When I run pip -v as a regular user, this is what I get:
Traceback (most recent call last):
File "c:\python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Python38\Scripts\pip.exe\__main__.py", line 4, in <module>
File "C:\Users\verhager\AppData\Roaming\Python\Python38\site-packages\pip\__init__.py", line 1, in <module>
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
File "C:\Users\verhager\AppData\Roaming\Python\Python38\site-packages\pip\_internal\__init__.py", line 1, in <module>
import pip._internal.utils.inject_securetransport # noqa
ModuleNotFoundError: No module named 'pip._internal.utils'
I have tried reinstalling, rebooting, running as Administrator, reinstalling pip with get_pip.py, but nothing has worked sofar.
When searching, I found several people having similar issues on different OSes. It seems like I've tried all suggested solutions, but nothing has worked for me sofar.
Reinstalling didn't solve my problem. That is, not before I really made sure that nothing was left behind.
My Python install was in C:\Python38\. After uninstalling python, this directory remained and contained some left over modules, like pip. I manually deleted the whole C:\Python38 folder.
Then, I checked my AppData folder in my home dir. Everything in this folder and all subfolders that was related to Python or Python modules, I deleted as well. Keep in mind AppData is a hidden folder, so it you might have to enable showing of hidden files and folders in the explorer first.
Finally, I removed all Python folders from my PATH environment variables (system as well as user).
After that, I did a new install of Python 3.8 and everything works as expected.
What I think the problem was? Some left overs from a previously (broken) installation messed with my environment, causing pip not resolving required modules.
I had the same error as you, with Windows 10. I also investigated and found that the "pip._internal.utils" package was missing. I was able to overcome this issue without an extensive Cleanup/Reinstall of Python.
After ensuring the following
That the Python Binary and Scripts folders were part of %PATH%
That I was on a Console Window with Administrator privileges
I ran the following command
python -m ensurepip --default-pip
With this command the package was installed. I did a general verification of the installation with the following command.
pip --version
Which returned the with specs. This command invokes the missing package.
I faced the same issue and here's how I resolved this error on windows 7 -
Navigate to C:\Users<user-name>\AppData\Roaming\Python\Python38\site-packages
Delete pip folder
This is introduced when I read this messsage
"You should consider upgrading via the 'python -m pip install --upgrade pip' comand." and followed using the same command for upgrading.

Pip install openslide completes successfully but when I import it "the specified module is not found"

I need to open SVS images in Python 3.7 and it seems that Openslide is the only module capable of opening images of that size (30k*30k pixels). I have used pip install openslide-python as well as python -m pip install openslide-python and pip 3 install... etc.
I know the module has been successfully installed because if I run any of those commands again the command line returns requirement already satisfied however when I run Python and try to import openslide it gives the error at the bottom.
My guess was that the .whl or .tar.gz files were in the wrong path so I made a bunch of copies and put them in the openslide folders within the Anaconda3 folder. The error persists. I have included the full error code below for clarity.
Extra: If I run help("modules") openslide shows up along with numpy, math, sklearn etc. I can import and run all other modules without issue.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\brimk\Anaconda3\lib\site-packages\openslide\__init__.py", line 29, in <module>
from openslide import lowlevel
File "C:\Users\brimk\Anaconda3\lib\site-packages\openslide\lowlevel.py", line 41, in <module>
_lib = cdll.LoadLibrary('libopenslide-0.dll')
File "C:\Users\brimk\Anaconda3\lib\ctypes\__init__.py", line 434, in LoadLibrary
return self._dlltype(name)
File "C:\Users\brimk\Anaconda3\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
My issue was resolved by the answer from my hero!
It seems that, at least for Openslide, running Python from the Path to the Bin is the easiest solution. It can be done this way.
Download the Windows Binary here.
Extract the download to whatever path you want.
Open command window
pip3 install openslide-python (pip2 if Python 2)
cd C:\Users\Path\to\Openslide-Win64-20171122\bin
python
import openslide
In the future you will have to run python from the path to the Openslide bin (Step 4). This can be done more rigorously by adding that file path to the PATH as described in detail here as well as in the answer above.

I am unable to successfully import pywinauto into python 3.6.4

I began with a pip install of "pywinauto" and attempted to import it, and I initially I got a message saying that the module win32api was missing. I attempted a pip install of that module but received a message saying that no satisfactory version could be found.
I then downloaded a copy of it from the web which when I tried to install it informed me that I don't have Python 3.6 installed on my system(!)
I had a number of installations of earlier versions and worried that they might be causing a problem so I deleted them and tried again, no success. The path to my executable is C:\Python36\python.exe.
I went to the site-packages folder and deleted the pywinauto and pywinauto-0.6.4-py3.6.egg-info folders and did a fresh pip install which concluded with the message: "Successfully installed pywinauto-0.6.4" and attempted to import it again.
This time I got the following:
import pywinauto
File "C:\Python36\lib\site-packages\pywinauto\__init__.py", line 72, in <module>
from . import findwindows
File "C:\Python36\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "C:\Python36\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
File "C:\Python36\lib\site-packages\pywinauto\controls\uiawrapper.py", line 46, in <module>
from ..uia_defines import IUIA
File "C:\Python36\lib\site-packages\pywinauto\uia_defines.py", line 181, in <module>
pattern_ids = _build_pattern_ids_dic()
File "C:\Python36\lib\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
if hasattr(IUIA().ui_automation_client, cls_name):
File "C:\Python36\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
File "C:\Python36\lib\site-packages\pywinauto\uia_defines.py", line 63, in __init__
self.ui_automation_client.CUIAutomation().IPersist_GetClassID(),
AttributeError: module 'comtypes.gen.UIAutomationClient' has no attribute 'CUIAutomation'
At this point I really don't know what to do. It appears that one of the imported files is lacking something that another one needs. I would be grateful for any ideas......
The correct dependency can be installed so:
pip install pywin32
Previously it was pypiwin32 but something is changed in these packages maintenance and pywin32 became official again. pywinauto 0.6.5 will reflect these changes soon.
The second issue looks like known comtypes issue with generating cache files for UI Automation type library. The workaround assumes running the script as Administrator at least first time to have an access to comtypes cache folder. Unfortunately comtypes maintainers are not so active and there are a number of pull requests with very similar fixes and they all still hang unaccepted.

Issues installing pywin32 behind proxy

I am trying to install pywin32 behind a proxy, and therefore I had to use the zip, rather than the .exe file available. I have down this with other packages and they work fine.
PS C:\Users\Michael.Spencer\Downloads\pywin32-221\pywin32-221> py -3 setup3.py build
Converting...
Executing...
Building pywin32 3.6.221.0
Traceback (most recent call last):
File "setup3.py", line 16
exec(str(got))
File "<string>", line 1944, in <module>
File "<string>", line 594, in __init__
File "C:\Program Files\Python36\lib\ntpath.py", line 75, in join
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType
I have never come across this issue when downloading packages manually. The only issue I can think of is my machine is 64 bit, and maybe the zip file only contains a 32 bit version? However from what I've read, that would result in a different errortype. Any help is appreciated thanks.
An alternate simpler way to install, just re-iterating from the comments, is instead of building from source would be,
pip install pypiwin32
and to install in a different directory, for whatever reason,
pip install --target=[path] pypiwin32
from
Install a Python package into a different directory using pip?

Using virtualenv with python3 in openSuSE

I am experiencing a problem when using virtualenv in openSuSE 12.3 with Python3:
I installed the python3 and python3-devel packages.
Then I installed the newest distribute and pip and finally virtualenv using pip.
When I try to create a virtualenv I get the following error:
$ virtualenv-3.3 venv01
Using base prefix '/usr'
New python executable in venv01/bin/python3.3
Also creating executable in venv01/bin/python
Installing distribute.........................................................................................................................................................................................................................................................................................................................................................................................................done.
Installing pip....
Complete output from command /home/user/venv01/bin/python3.3 -x /home/user/venv01/bin/easy_install /usr/local/lib/pytho...ort/pip-1.3.1.tar.gz:
/home/user/venv01/bin/python3.3: can't open file '/home/user/venv01/bin/easy_install': [Errno 2] No such file or directory
----------------------------------------
...Installing pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv-3.3", line 9, in <module>
load_entry_point('virtualenv==1.9.1', 'console_scripts', 'virtualenv-3.3')()
File "/usr/local/lib/python3.3/site-packages/virtualenv.py", line 979, in main
no_pip=options.no_pip)
File "/usr/local/lib/python3.3/site-packages/virtualenv.py", line 1094, in create_environment
install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
File "/usr/local/lib/python3.3/site-packages/virtualenv.py", line 667, in install_pip
filter_stdout=_filter_setup)
File "/usr/local/lib/python3.3/site-packages/virtualenv.py", line 1057, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/user/venv01/bin/python3.3 -x /home/user/venv01/bin/easy_install /usr/local/lib/pytho...ort/pip-1.3.1.tar.gz failed with error code 2
Running it with -vvv yields some interesting output that shows that distribute
is extracted to <venv>/local/lib/python3.3/site-packages/.
I wonder why distribute is not installed into <venv>/lib/python3.3/site-packages/?
Does anyone have an idea why this happens and how I can use virtualenv in
openSuSE without compiling python3 myself?
[now fixed in latest patches from opensuse]
[oh! i just realised you are the same person as the original link. sorry. but i will leave this as it is a top result for google search on this issue (was searching myself for any update) so it may help others.]
this is a known issue, discussed at https://forums.opensuse.org/english/get-technical-help-here/applications/484475-using-virtualenv-python-3-a.html and with an open bug at https://bugzilla.novell.com/show_bug.cgi?id=809831
the only work-around i know of is to install everything yourself. it's not so hard, and i describe what is necessary at http://www.acooke.org/cute/GettingPyt0.html
basically:
install python 3.3 from source (do an "altinstall" to install as /usr/local/bin/python3.3)
fix the lib issue (link lib_dynload from /usr/local/lib64/python3.3 to /usr/local/lib/python3.3)
install distutils
install virtualenv
then you can use python3.3 and virtual-env-3.3 etc as expected.

Resources