I know many questions speak about this problem, but i tried a lot and didn't fin any solution to my "very classical" issue : Python import fails altough package installed:
MacBook-Pro-de-Stephanie:scripts user$ sudo -H pip install openpyxl
Collecting openpyxl
Requirement already satisfied (use --upgrade to upgrade): jdcal in /usr/local/lib/python2.7/site-packages (from openpyxl)
Requirement already satisfied (use --upgrade to upgrade): et-xmlfile in /usr/local/lib/python2.7/site-packages (from openpyxl)
Installing collected packages: openpyxl
Successfully installed openpyxl-2.3.5
Package installed right ?
MacBook-Pro-de-Stephanie:scripts user$ python interactionsXLSX2CSV.py
Traceback (most recent call last):
File "interactionsXLSX2CSV.py", line 5, in <module>
from openpyxl import load_workbook
ImportError: No module named openpyxl
Fails right ?
MacBook-Pro-de-Stephanie:scripts user$ echo $PYTHONPATH
/usr/local/lib/python2.7/:
Path seems ok, no ?
I set permissions with:
sudo chmod -R ugo+rX ./lib/python2.7/site-packages/
What can i try else ?
Thank you very much
Here was the solution for me (linked to Mac OS clearly) : Can't load Python modules installed via pip from site-packages directory
/usr/bin/python is the executable for the python that comes with OS
X. /usr/local/lib is a location for user-installed programs only,
possibly from Python.org or Homebrew. So you're mixing different
Python installs, and changing the python path is only a partial
workaround for different packages being installed for different
installations.
In order to make sure you use the pip associated with a particular
python, you can run python -m pip install <pkg>, or go look at what
the pip on your path is, or is symlinked to.
I am not getting that error. Just now i installed. All i am getting is
" /usr/local/lib/python2.7/dist-packages/openpyxl/xml/init.py:15: UserWarning: The installed version of lxml is too old to be used with openpyxl
warnings.warn("The installed version of lxml is too old to be used with openpyxl")"
Once try by using below command.
sudo apt-get install python-openpyxl
Related
I am trying to run an audio file in Python:
from playsound import playsound
def main():
playsound('audio.mp3')
main()
However, I keep getting the following error:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/playsound.py", line 55, in _playsoundOSX
from AppKit import NSSound
ImportError: No module named 'AppKit'
I am using Python 3.5.4 on macOS 10.12.6. I have tried installing it via pip but I am returned this error:
Using cached AppKit-0.2.8.tar.gz
Requirement already satisfied: flask in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from appkit)
Collecting pygobject (from appkit)
Could not find a version that satisfies the requirement pygobject (from appkit) (from versions: )
No matching distribution found for pygobject (from appkit)
If you want to use AppKit you have to install PyObjC:
pip3 install -U PyObjC
or
pip install -U PyObjC
If anybody else stumbles upon this error when using this library, trying to do exactly as #user5124826 first stated in the question, as long as you have you have done a:
pip3 install AppKit
or
pip install AppKit
And also installed PyObjC...Wherever you have your packages installed, for example, pip when used with virtualenv will generally install packages in the path
virtualenv_name>/lib//site-packages.
Look for the AppKit package, and it will most likely be in all LOWERCASE. So it would be appkit. Just change this folder to 'AppKit', and you should be good to go
Ran into the same problem (suddenly, probaby after some system upgrade of brew, etc.).
I solved it by reinstalling from scratch, following iTerm's docs.
pip uninstall appkit
pip uninstall iterm2
pip list | grep pyobjc | cut -d ' ' -f 1 | xargs pip uninstall -y
then, depending on your system
pyenv rehash
then reinstall only iterm2
pip install iterm2
According to the docs, iterm2 has pyobjc as a dependency and it all provides AppKit, so no additional installation needed.
In my case, it works only in Python 2.7. Because Python 3 requires small letters, in import appkit you get the error.
I have updated a library to work with small caps import: https://github.com/TinKurbatoff/appkit
This question has been asked a few times, but the remedy appears to complicated enough that I'm still searching for a user specific solution. I recently re-installed anaconda; now, after entering
"pip install splinter"
in the Terminal on my Mac I get the response:
"Requirement already satisfied: splinter in /usr/local/lib/python2.7/site-packages
Requirement already satisfied: selenium>=2.53.6 in /usr/local/lib/python2.7/site-packages (from splinter)"
But, I get the following error in python (Anaconda) after entering import splinter
Traceback (most recent call last):
File "", line 1, in
import splinter
ImportError: No module named splinter"
When I enter which python in the terminal, this is the output: "/usr/local/bin/python"
I am editing the question here to add the solution: ~/anaconda2/bin/pip install splinter
1) Try uninstalling and the re install it:
pip uninstall splinter
2) Also manually delete splinter from "site-packages".
3)Also try this if problem still persists:
$ easy_install -m PACKAGE_name
those are two different pythons. you are using the pip from your default python, but trying to import the package from anaconda.
use
$ dirname `which python`
to see where the anaconda's python executable is, then see that folder for pip. now use this pip to install the package
I had the same issue, I uninstalled and reinstalled splinter many times but that didn't work. Then I typed source activate (name of my conda environment) and then did pip install splinter. It worked for me.
When I run !pip install geocoder in Jupyter Notebook I get the same output as running pip install geocoder in the terminal but the geocoder package is not available when I try to import it.
I'm using Ubuntu 14.04, Anaconda 4.0.0 and pip 8.1.2
Installing geocoder:
!pip install geocoder
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting geocoder
Downloading geocoder-1.15.1-py2.py3-none-any.whl (195kB)
100% |████████████████████████████████| 204kB 3.2MB/s
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/dist-packages (from geocoder)
Requirement already satisfied (use --upgrade to upgrade): ratelim in /usr/local/lib/python2.7/dist-packages (from geocoder)
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from geocoder)
Requirement already satisfied (use --upgrade to upgrade): click in /usr/local/lib/python2.7/dist-packages (from geocoder)
Requirement already satisfied (use --upgrade to upgrade): decorator in /usr/local/lib/python2.7/dist-packages/decorator-4.0.10-py2.7.egg (from ratelim->geocoder)
Installing collected packages: geocoder
Successfully installed geocoder-1.15.1
Then try to import it:
import geocoder
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-603a981d39f2> in <module>()
----> 1 import geocoder
ImportError: No module named geocoder
I also tried shutting down the notebook and restarting it without any luck.
Edit: I found that using the terminal installs the geocoder package in /home/ubuntu/.local/lib/python2.7/site-packages and using a notebook installs it in /usr/local/lib/python2.7/dist-packages which is not in the path. sys.path.append('/usr/local/lib/python2.7/dist-packages') solves the problem for the current session.
So how can I permanently modify the path or tell pip where to install geocoder?
In IPython (jupyter) 7.3 and later, there is a magic %pip and %conda command that will install into the current kernel (rather than into the instance of Python that launched the notebook).
%pip install geocoder
In earlier versions, you need to use sys to fix the problem like in the answer by FlyingZebra1
import sys
!{sys.executable} -m pip install geocoder
! pip install --user <package>
The ! tells the notebook to execute the cell as a shell command.
%pip install fedex #fedex = package name
in 2019.
In older versions of conda:
import sys
!{sys.executable} -m pip install fedex #fedex = package name
*note - you do need to import sys
In jupyter notebook under python 3.6, the following line works:
!source activate py36;pip install <...>
The problem is that pyarrow is saved by pip into dist-packages (in your case /usr/local/lib/python2.7/dist-packages). This path is skipped by Jupyter so pip won't help.
As a solution I suggest adding in the first block
import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages')
or whatever is path or python version. In case of Python 3.5 this is
import sys
sys.path.append("/usr/local/lib/python3.5/dist-packages")
This worked for me in Jupyter nOtebook /Mac Platform /Python 3 :
import sys
!{sys.executable} -m pip install -r requirements.txt
Try using some shell magic: %%sh
%%sh pip install geocoder
let me know if it works, thanks
Alternative option :
you can also create a bash cell in jupyter using bash kernel and then pip install geocoder. That should work
I had the same problem.
I found these instructions that worked for me.
# Example of installing handcalcs directly from a notebook
!pip install --upgrade-strategy only-if-needed handcalcs
ref: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Issues may arise when using pip and conda together. When combining
conda and pip, it is best to use an isolated conda environment. Only
after conda has been used to install as many packages as possible
should pip be used to install any remaining software. If modifications
are needed to the environment, it is best to create a new environment
rather than running conda after pip. When appropriate, conda and pip
requirements should be stored in text files.
We recommend that you:
Use pip only after conda
Install as many requirements as possible with conda then use pip.
Pip should be run with --upgrade-strategy only-if-needed (the default).
Do not use pip with the --user argument, avoid all users installs.
conda create -n py27 python=2.7 ipykernel
source activate py27
pip install geocoder
Using pip2 worked for me:
!pip2 install geocoder
...
import geocoder
g = geocoder.google('Mountain View, CA')
g.latlng
[37.3860517, -122.0838511]
I recently reformatted my computer, and I've been trying to reinstall Python and Pip and the modules I use for programming. However, when I try to install modules with pip in powershell, for example "pip install BeautifulSoup", it displays
PS C:\Users\Norman\Copy\Coding\LinguisticsProject> pip install BeautifulSoup
Downloading/unpacking pip
Downloading/unpacking setuptools
Downloading/unpacking install
Could not find any downloads that satisfy the requirement install
Some externally hosted files were ignored (use --allow-external install to allow).
Cleaning up...
No distributions at all found for install
Storing debug log for failure in C:\Users\Norman\pip\pip.log
The log file can be found at http://pastebin.com/Th7uuKA4. The module is not installing correctly, because the module is not found when I try to import it. I have my user PATH variable set to the following: http://pastebin.com/htquhuVY. Thanks!
I believe the package you are looking for is BeautifulSoup4. I failed this too. I feel your pain.
I install virtualenv with command sudo /usr/bin/pip-2.6 install virtualenv
And it says
Requirement already satisfied (use --upgrade to upgrade):
virtualenv in /usr/local/lib/python2.6/dist-packages
Cleaning up...
Why pip from /usr/bin looks to /usr/local/lib?
I need to install virtualenv scripts directly to /usr/bin, so I write
sudo /usr/bin/pip-2.6 install --install-option="--install-scripts=/usr/bin" virtualenv
But again it responds with
Requirement already satisfied (use --upgrade to upgrade):
virtualenv in /usr/local/lib/python2.6/dist-packages
Cleaning up...
Adding --upgrade doesn't help.
How can I install virtualenv scripts to /usr/bin ?
For your current issue can you first uninstall virtualenv using pip, and then reinstall using --script-dir=DIR, -s DIR as an --install-option.
As for your issue running pip with extra arguments and install not seeming to do anything, that may be fixed on develop branch at https://github.com/pypa/pip if not please file a bug with us on the GitHub issue tracker for pip.
As to why it is behaving like this - the install is based on the python installation not on the location of pip. Pip uses setuptools/distribute under the hood and conforms to the configuration of the python it is running under.
You can see where the version of python you are using installs to by running it - in this case probably python2.6 and querying the sys module.
>>> import sys
>>> sys.prefix
>>> sys.exec_prefix
See also distutils.sysconfig
For more information:
Installing Python Modules
setuptools
distribute
Try:
sudo /usr/bin/pip-2.6 install --install-option="--prefix=/usr/bin" virtualenv
(source).