Python not recognizing installed dependencies - python

I am running Python version 2.7.12 a windows system without internet access and have manually installed modules. However when trying to run a script requiring matplotlib.pyplot and after installing the dependencies dateutil it is still not working.
I am still receiving the error:
What is the reason for the error? I have been troubleshooting the problem for a long time.

Try using Pip to install the package. You can download a copy of dateutil 2.5.3 from here https://pypi.python.org/pypi/python-dateutil/2.5.3.
Once downloaded, navigate to the folder where you downloaded the dateutil package, and install the package with pip:
pip install python_dateutil-2.5.3-py2.py3-none-any.whl
After the module is installed, simply import as normal in the console or script:
import dateutil
And here is a quick example:
If you need to install pip, here are some instruction to install pip.

Related

Unable to import package 'pdfrw'

Did pip install pdfrw, uninstalled and reinstalled, restarted my laptop, but still unable to import the specified package as it returns error: No module named 'pdfrw'.
https://pypi.org/project/pdfrw/#pdfrw-philosophy
Any advice is appreciated.
Update: Tried installing by cmd, I'm using Jupyter Notebook as IDE :)
You have to make sure that the Python that you are using with Jupyter Notebook is the same that the one for which you are installing that package. If you have several Python interpreters installed or if you installed Ananconda to use Jupyter, you have to take care of which pip are you invoking from CMD.
If you are using Jupyter from Ananconda, try to install the package using conda.
conda install pdfrw
Another thing that you can do is open a Command Prompt and type:
where python
you will get the path to the interpreters that you have installed. In my case I get:
>>> C:\Windows\system32>where python
C:\Python39\python.exe
C:\Python38\python.exe
>>> C:\Windows\system32>where pip
C:\Python39\Scripts\pip.exe
C:\Python38\Scripts\pip.exe
Then you can use a concrete interpreter to call pip, in my case I will do:
C:\Python39\python.exe -m pip install pdfrw
After the installation finish, invoke the same interpreter you use to call pip:
C:\Python39\python.exe
Then try to import pdfrw. If you can import it, then the problem is that you are using a different interpreter in Jupyter Notebook.

Installing numpy for Python 2.7 while also having Python 3.4 installed?

I have both Python 2.7 and Python 3.4 (and have to have both because for the class I'm running, students have the option of using either). One student has used Python 2.7 and numpy for their project, but when I attempt to install numpy, it installs it to 3.4. I need to install it to 2.7.
I'm using numpy 1.9 from this site, which I'm told is also 2.7-specific: http://sourceforge.net/projects/numpy/files/NumPy/
However, nonetheless it still goes to the 3.4 folder. Copying it to Python 2.7 didn't work, obviously.
How do I do this?
I recommend installing with pip.
pip install numpy
If this doesn't work on windows then download the binary from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and convert it to a wheel before installing.
pip install wheel
wheel convert path/to/binary
pip install numpy_wheel
Pip is recommended because you can uninstall.
To check where you are installing to
pip -V
You may have an environmental variable path to the wrong pip.
Assuming that you are using, or at least you should use pip to install the library. You can specify the python version to be installed by changing the suffix, e.g. pip-2.7 install numpy.
pip install numpy
pip-2.7 install numpy
pip-3.4 install numpy
As an alternative, in case that you do not want to use pip is to download and install the library using setup with a similar technique.
python setup.py install
python2.7 setup.py install
python3.4 setup.py install
Your PATH isn't setup correctly.
C:> where pip
Should tell you which pip it is trying to use, and it is likely whichever one it found on your PATH first...
So, instead, you will want to run it as
C:> C:\mypython2install\pip.exe install numpy
Or, setup your path correctly. See here
Just one other note on issues like this. I had a similar problem with Python 2.7 libraries not being found, because I had miniconda installed for a Python virtual environment that was hijacking calls to python from other programs. After deleting the minconda directory in my home the problem went away and python libraries that were properly installed were found again.
Note-This answer is particularly for Windows PC which has both Python2 & Pyhton3 installed on it.
Both the versions of Python has their different directories somewhat like
"C:\Python27\" ----for python2
"C:\Python35\" ---- for python3
*(or it depends on what path you chose while installing Python**)*
pip GENERALLY exist under the directory "C:\Python**\Scripts"
there you can find exe files like:
pip.exe/pip2.exe/pip2.7.exe ----for python2
pip3.exe/pip3.5.exe ----for python3
to install packages on python2:
use
Python27\Scripts\pip2.exe install package_name
(where the 1st argument is the path of exe file, it might differ for your system)
to install packages on python3:
use
Python35\Scripts\pip3.exe install package_name
there is no need to uninstall any version of python to achieve the task.

Python: pip installing requests for older version: 2.7

I'm trying to interface with an API using a python program that only works in 2.7 and not in 3.4 which is also installed on my machine. However, one of my program's dependencies is the requests module. I have requests available in my 3.4 environment, but in 2.7 import requests results in:
import error: no such module named requests
Many Stack Overflow Q&A's have reccomended installing requests for 2.7 using: pip2.7 install requests, but apparently I don't have pip2.7 because that results in:
'pip2.7' is not recognized as an internal or external command
Question: How can I get pip2.7 instead of my default pip? Is it a seperate version of pip or do I just need to tell my current version I'm trying to install for version 2.7 not 2.4?
Note: The suggested solution to use easy_install-2.7 -U pip to install pip2.7 doesn't run on my Windows7 maching, the command propmt prints : easy_instal-2.7 is not recognized as an internal or external command
By default 3.4 won't create the plain pip command but it can be enabled with an option which is presumably what has been done in your case. Since there are other names for the Python 3 pip you can safely overwrite it by installing the 2.7 pip on top of it with easy_install.
Since this is Windows, your Python binaries are kept in isolated directories so you should just ensure that the 2.7 directory is first in the path variable. Look in the <python root 2.7>\Scripts directory to see if you have an easy_install already. If not you need to install setuptools.

ImportError: no module named win32api

I am using Python 2.7 and I want to use pywin32-214 on Windows 7. I installed pywin32-214 by using the MSI installer. But when I import win32api in my Python script, it throws the error:
no module named win32api
What should I do? How can I use win32api on Windows 7?
This is resolve my case as found on
Where to find the win32api module for Python?
pip install pypiwin32
According to pywin32 github you must run
pip install pywin32
and after that, you must run
python Scripts/pywin32_postinstall.py -install
I know I'm reviving an old thread, but I just had this problem and this was the only way to solve it.
I had an identical problem, which I solved by restarting my Python editor and shell. I had installed pywin32 but the new modules were not picked up until the restarts.
If you've already done that, do a search in your Python installation for win32api and you should find win32api.pyd under ${PYTHON_HOME}\Lib\site-packages\win32.
I didn't find the package of the most voted answer in my Python 3 dist.
I had the same problem and solved it installing the module pywin32:
In a normal python:
pip install pywin32
In anaconda:
conda install pywin32
My python installation (Intel® Distribution for Python) had some kind of dependency problem and was giving this error. After installing this module it stopped appearing.
I had both pywin32 and pipywin32 installed like suggested in previous answer, but I still did not have a folder ${PYTHON_HOME}\Lib\site-packages\win32.
This always lead to errors when trying import win32api.
The simple solution was to uninstall both packages and reinstall pywin32:
pip uninstall pipywin32
pip uninstall pywin32
pip install pywin32
Then restart Python (and Jupyter).
Now, the win32 folder is there and the import works fine. Problem solved.
After installing pywin32
Steps to correctly install your module (pywin32)
First search where is your python pip is present
1a. For Example in my case location of pip -
C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts
Then open your command prompt and change directory to your pip folder location.
cd C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts
C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts>pip install
pypiwin32
Restart your IDE
All done now you can use the module .
The following should work:
pip install pywin32
But it didn't for me. I fixed this by downloading and installing the exe from here:
https://github.com/mhammond/pywin32/releases
This line:
import win32com
got me the error no module named win32api.
Using this command in elevated terminal:
pip install pywin32-ctypes and
pip install pywin32
and based on the error displayed, replacing:
import win32api → from win32ctypes.pywin32 import win32api
import pywintypes → from win32.lib import pywintypes
import _win32sysloader → from win32 import _win32sysloader
in your source file, or even the files of the packages that report the error (know what you are doing if you choose this approach) may solve this error. But better would be to just add the corresponding directories into the python path variable, for better integration with the python loading system, more info here: https://realpython.com/python-import/
So I put this content:
python38.zip
.
./lib
./lib/site-packages
./lib/site-packages/win32
./lib/site-packages/win32/lib
./lib/site-packages/win32ctypes/pywin32
./lib/site-packages/win32ctypes
# Uncomment to run site.main() automatically
#import site
(order DOES matter)
into this file: <python_root_installation_directory>/python38._pth
That way, correct libraries load when standard imports are used. If there is a cache import somewhere in the library, it will work, and the imports inside the libraries work as well.
This works for me and my installation, so your environment may be set up differently and this guide may not be fully compatible, but it is a good step in solving the issue, maybe modification or extension of my steps above may lead to the solution in another distribution.
Try this, it worked for me, it may help you!
pip install pywin32==225
I've tried all of your answers and finally got a solution. my issue was that I installed from both pip and python interpreter on my Pycharm IDE. I just removed win32compact from my interpreter and it works.
let me summarize, correct me if wrong, as below:
# update to newest pywin32
python -m pip install -U pywin32 pypiwin32
# run the post-install #ref https://stackoverflow.com/questions/21343774/importerror-no-module-named-win32api
python %CONDA_PREFIX%\Scripts\pywin32_postinstall.py -install
# double check
python -c "print( __import__('win32api') )"
In my case, the only thing that worked was to download the appropriate wheel from: https://pypi.org/project/pywin32/#files, and install with --force-reinstall.
pip install pywin32-300-cp37-cp37m-win_amd64.whl --force-reinstall
I found solution here:
https://www.ti-enxame.com/pt/python/pywin32-e-python-3.8.0/813327700/
I was able to run it on Spyder without error, but It wasn't working on cmd prompt
I just import the module pywintypes before win32api
import pywintypes
import win32api
I tried to reinstall pywin32, installed different versions, but nothing could make pywin work. The only thing that did finally help me was running
python pywin32_postinstall.py
which is located at Anaconda3\Scripts folder. Thanks for sameer_nubia for highlighting the location.
I solve this by
python -m pip install -U pywin32 pypiwin32

Import Error: No module named AppKit

I use Mac OS X Lion and Python 2.7. I am new to python. Can anyone tell me how to import AppKit and PyObjC to Python. But i get the errors when trying to import Import Error: No module named AppKit or 'Import Error: No module named PyObjC.
Trying easy_install does not help either.
What can i do to import these 2 modules?
If not already installed, install pip by running:
sudo easy_install pip
Then run:
## install for all users
sudo pip install pyobjc
or
## install for current user only
pip install pyobjc --user
NOTE: the general recommendation is to avoid using the system python, and use instead a user-maintained version, for example installed via brew install python3, macports, conda or whatever you already use for third party dependencies.
If you're on Mac it could be you're using the incorrect pip version, try sudo pip3 install -U pyobjc that solved it for me.
This a good guide on how to install PyObjc: http://ioanna.me/2009/09/installing-pyobjc-xcode-templates-in-snow-leopard/
When I was trying to install PyObjc I found it quite hard, but after a while, (and lots of google searches) I got it working.
Edit
I've found a more modern guide on how to do this. Download the templates and put them into your ~/Library/Developer/Xcode/Templates/ directory, and everything should work correctly.
If you are using PyCharm, you should install PyObjC package manually within it because of venv I guess. This was the only working solution for me.
In my case none of them worked. I was using Anaconda in my mac, later I discovered that the main issue with the Anaconda. Then I installed PyObjC with it's all supporting libraries inside Anaconda in a specific Environment.
I run the command line by clicking the Environment play icon and run my script.
It worked without any issues :)

Categories

Resources