I'm stuck with an issue. I have a Python script that I would like to run on my OSX but seems that I crossed on many issues.
To run the script I should have both Python and Moviepy installed.
To install Moviepy I used this command:
sudo pip install moviepy
The response was:
sudo: pip: command not found
So I tried to install pip, with the command:
sudo easy_install pip
And got this answer:
Searching for pip
Best match: pip 9.0.1
Processing pip-9.0.1-py2.7.egg
pip 9.0.1 is already the active version in easy-install.pth
Using /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
I tried to run again the
sudo pip install moviepy
but I still got that issue. What I should do?
UPDATE:
not sure on OSX, but can u try pip3 – Rehan Azher 23 mins ago
sudo pip3 install moviepy
Password:
sudo: pip3: command not found
It seems that pip is not in your path, but as long as Python can find it: sudo python -m pip install moviepy should do it. Check your $PATH env. variable, tho. – zwer 14 mins ago
sudo python -m pip install moviepy
/usr/bin/python: No module named pip
UPDATE2
A good option for you is to consider installing pip using one of OSX's
sources, like the apt program in Debian-based distributions, rather
than easy_install. – Shiva 4 hours ago
sudo apt install moviepy
Password:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/apt" (-1)
No idea why everyone keeps getting stuck on this. You have a
fundamental decision to make when using Python. You either run Python
2.7 that Apple ships and which is ancient and doesn't have pip or you use homebrew and install Python3 and pip3 and put /usr/local/bin at
the start of your PATH. But don't try a mixture of the two. – Mark
Setchell 3 hours ago
Tried to install homebrew but it cannot find the package moviepy that I am looking for.
Try with this:
pip3 install package-name
This works for me!
Yes, it's a mess. Today, your best option is to leave the ageing, OS-provided version of Python (all the stuff in /Library/Python and similar) alone and start fresh.
It looks like you've already done this (since you have an executable at /usr/bin/python) but if not, the easiest way to get Python 2 is to use Homebrew. Install Homebrew using the instructions on the website and then use it to install Python:
brew install python#2
Python 2.7.9+ comes with pip already, but if you've ended up with an older version then use python itself and get-pip.py to install pip (instead of easy_install, which is deprecated):
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Note that get-pip.py includes a copy of pip in order to install pip effectively. Yes, things are that bad.
Finally, note that Python 2 will be end of life in less than 6 months. If you have the luxury, consider skipping straight to Python 3. Then it's as easy as:
brew install python
because pip3 comes with python3 since version 3.4. Homebrew manages to handle the installation of both Python 2 and Python 3 without conflict.
Note this procedure is different on every operating system and every month or two. But at least it should get you going for the foreseeable future.
Can you go to python shell and type import pip? If that works, then it means the pip package is installed, but there is no command-line script/program available.
In my computer, the command-line pip program is actually a python script in itself, and is located in /usr/local/bin/, which is in my PATH. Below are the contents of my pip script.
#!/usr/bin/python
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
This is a dirty trick. What you could do is to create a new file called pip in your /usr/local/bin/ directory (or similar for OSX) and copy the above lines into it.
sudo touch /usr/local/bin/pip # create a new empty file called "pip"
# ... open the file in your favorite editor, copy the above contents and save the file
sudo chmod +x /usr/local/bin/pip # make it executable
The first line in the file (#!/usr/bin/python), called "Shebang", points to the program that should execute this file when you run it on your command-line. You should put the path to the python program in your computer over there.
Related
WARNING: pip is being invoked by an old script wrapper. This will fail
in a future version of pip. Please see
https://github.com/pypa/pip/issues/5599 for advice on fixing the
underlying issue. To avoid this problem you can invoke Python with '-m
pip' instead of running pip directly.
When I directly type pip list to the terminal, I get the above warning. What does it mean exactly?
Should I always use it as python3 -m pip list? If I use it in that way, same output (list of packages) comes up without any warning.
p.s. : I am on ubuntu 18.10
I faced the same issue but on Windows. Reinstalling pip worked for me. You can force a reinstall of pip with:
python -m pip install --upgrade --force-reinstall pip
For Python3 Versions:
python3 -m pip install --upgrade --force-reinstall pip
I also faced the same problem when I switched to zsh shell from bash.
The solution was simple but I didn't notice it at first.
After I installed pip, I saw this warning
pip is being invoked by an old script wrapper
First I tried this solution
python3.8 -m pip install --upgrade --force-reinstall pip
But then I ran into this issue:
Then I searched how to add PYTHONPATH. I opened my .zshrc and say these lines were commented
# If you come from bash you might have to change your $PATH.
I uncommented the line that followed, and my misery vanished.
Now when I ran,
python3.8 -m pip install --upgrade --force-reinstall pip
Then the warnings of not in path disappeared in thin air, leaving me with a clean output.
I hope this would help anybody who ran into the same problem.
Let me preface this by saying I am still very green with python and linux in general so I may be off base with my guidance here but I digress...
You might want check the location of the pip module you are invoking when you use the pipcommand. for me, I found out that when I would update and modify the pip command, it would update the pip file on my ~/.local/bin directory but when I would run it, it would default to the pip command located in the /usr/local/bin directory.
run the command
pip install --upgrade pip
for me this command returned:
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: pip in ./.local/lib/python3.6/site-packages (20.1.1)
Note the file location and version (in bold).
check your path variables and the default pip that executes default by running the these 2 commands respectively
echo $PATH
and
which pip
god willing, they'll be congruent otherwise you'll have to either alter your the path variable directories making sure that the directory for your desired pip module is first or you'll have to delete the pip file from the director that you dont want use (i.e. the directory that came up when you ran which pip if that is not the same as the directory listed when you updated pip)
For me, removing the pip files in the usr/local/bin worked like a charm. Also check that the pip files that you want to use are referencing the correct version of python at the top of their scripts
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
The other file originally referenced usr/bin/python (Python 2.7) instead of usr/bin/python3 (python 3.6.9) as I wanted initially.
Like I said before, I am just getting started with linux and python so take this with a grain of salt. Nevertheless, I no longer get this pip warning after taking these steps. Let me know if this helps at all.
I've encountered the same problem after I updated pip to 20.1.x version through Pycharm. I've found one way to ensure that you can use pip install xxx in emergency case:
Open the folder containing pip (e.g. C:\Program Files\Python37\Lib in my win10 laptop)
You may find two folders separately belongs to the old version pip and newly installed pip (e.g. ./pip19_xxx for your old one and ./pip for the newly installed one
Delete the folder of the new version pip (e.g. ./pip)
(IF NECESSARY) Change environment PATH in windows10
Test pip install xxx or python -m pip install xxx in cmd, it should work by now
After the PIP upgrade, because the boot file (/usr/bin/pip) has not been changed, the old boot file is still used,
Old PIP startup file:
#!/usr/bin/python3
# GENERATED BY DEBIAN
import sys
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
sys.exit(main())
New PIP startup file:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
The solution is as follows:
vi open /usr/bin/pip to add new code to save,
After this operation, there is no need to add "python -m" to run pip, and there will be no warning
You can solve it by upgrading pip:
pip install --upgrade pip
You can solve this by executing the following commands.
python -m pip install --upgrade --force-reninstall pip
Add python to the path in ~/.bash_profile.
like PATH=$PATH:/usr/local/bin
Just use
python -m pip install [module_name]
This will resolve warning issue
This worked for me.
python3 -m pip install <package name>
You can solve this problem by doing the following
1.Check that you are not having two versions of python.If you are having then uninstall one.
If the problem does not resolve after doing these then uninstall all the python installed in your pc and then again install it.
I ran into the same issue on Ubuntu 18.04 with python 3.6 after I ran pip3 install --upgrade pip. (The original pip version installed by apt install python3-pip was 9.0, but I wanted pip >= 10.0 so I could use pip list -v.)
Step 1: Check the pip paths
I found that there were several pips installed in various locations on my machine, and it was causing problems. Use these commands to see which pips are being executed.
pip --version
pip3 --version
type -a pip pip3 # show all the locations for pip and pip3
Step 2: Fix the pip paths
This step will be highly individual. You have to figure out for yourself which one to keep and which ones to remove. Here are some example commands that may be helpful:
# remove ~/.local/bin/pip
cd ~/.local/bin
mv pip pip.bak
hash -r # important, reset bash command cache!
# remove the old pip 9.0
sudo apt purge python3-pip
Step 3: Upgrade pip
Run the commands from Step 1 again to verify everything looks good. Then upgrade pip:
pip3 install --upgrade pip
# if you get permission denied above, the install for --user
pip3 install --user --upgrade pip
# validate everything looks right
pip --version
pip3 --version
type -a pip pip3 # show all the locations for pip and pip3
I know this question has been asked and answered a number of times but none of those solutions have worked for me. I have installed Python 2.7 into a local directory and added it to my path. When I try to install numpy i get the following error:
ImportError: No module named setuptools
I cannot simply sudo apt-get install python-setuptools because i don't have root access.
I need to install numpy and ideally have pip working for future applications.
0) Try to install packages that are isolated to the current user, use the --user flag:
pip install --user SomeProject
1a) I agree with #Pi Marillion here, use an isolated conda environment if you don't have root access. This way you keep your path clean.
To install conda:
Since I don't know about your OS, go to https://docs.conda.io/en/latest/miniconda.html
After installation, update your conda (just in case):
conda update conda
To list the installed packages, you can do
conda list
You should see python installed. you can start an interpreter by typing python in the terminal.
There's conda cheat sheet that I found incredibly helpful:
https://docs.conda.io/projects/conda/en/latest/user-guide/cheatsheet.html
b) Now try installing via pip and I think you might need python 3.x for setuptools.
https://packaging.python.org/tutorials/installing-packages/#id13
2) If this does not work you can still try
https://packaging.python.org/guides/installing-stand-alone-command-line-tools/
Hope this helps :)
First try easy_install --user setuptools pip. If that doesn't work you need to install things manually.
Download setuptools-*.zip from https://pypi.org/project/setuptools/#files. Unzip the archive, cd into the new directory and run python2.7 setup.py install.
Then try pip install. If it still doesn't work reinstall pip: download get-pip.py and run python get-pip.py --user.
I am trying to install jupyter on mac,
I understand that the mac comes with python version installed
But i also installed brew and installed python through brew.
When i check python location i get:
which python
/usr/bin/python
When i check pip location i get:
which pip
/usr/local/bin/pip
When i try to install jupyter:
pip install install
after a long installation it tried to remove python package that it want's to upgrade
And fails:
On trying to uninstall dateutil.
I think its the mac packages.
I tried with sudo, no change.
As far as i can understand it because the files are immutable.
Tried to remove the immutable with:
chflags uchg.
No change.
I also tried to work with virtual env, using:
sudo pip install virtualenvwrapper.
But that pip tries to uninstall another python folder.
Any suggestions?
Thanks
UPDATE:
The brew seems to create links from python2. to python2
And the same for python3.
I tried to create the link myself, It worked and i was manage to install the package i wanted. But its not a good solution,
The all point of brew is to manage this things for me, next time i will upgrade python it will break.
Any suggestions why? could it be because the brew installed two python version on my laptop?
RESOLVED:
Found the answer, thanks to #tdube question i went and looked what brew guys did to python and found this thread from Jan 17.
I turns out that they changed the behavior or installing python.
No you don't have simply python any more.
You have python2 and python3.
No more simply pip, now you have pip2 and pip3.
That is a major change from the default behavior of how people use python
Especially that mac comes with a default python
so now you have
python that is /usr/bin/python
python2 that is /usr/local/bin/python2
python3 that is /usr/local/bin/python3
this is the fix, the brew guys suggest ( you can see it when running brew info python ):
==> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.zshrc:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
Pip and setuptools have been installed. To update them
pip2 install --upgrade pip setuptools
You can install Python packages with
pip2 install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: http://docs.brew.sh/Homebrew-and-Python.html
You can read about it in this thread:
The Python that comes "pre-installed" on Mac is located in /usr/bin/python. I think you need to change the order of the entries in your PATH environment variable as noted here (python homebrew by default). Which file your PATH is set in depends on which shell you are using.
Having a weird problem with pip on os x.
As far as I can recall (and a quick look at my .bash_history seems to confirm) I have not made any recent changes to my configuration. Alas, the pip command seems to be suddenly using a different version of python than it was previously. Up until now I was using the command pip to manage my python2 libraries and pip3 to manage by python3 libraries. Suddenly, any attempts at running pip install fails with errors like missing parenthesis around print statements.
Here is the result of a few commands I attempted to figure out the problem:
which pip > /usr/local/bin/pip
which pip3 > /usr/local/bin/pip3
which python > /usr/local/bin/python
python version > Python 2.7.11
pip --version > pip 8.1.1 from /usr/local/lib/python3.5/site-packages (python 3.5)
So for some reason the pip command seems to be running from the PyPi2 database but in python3 now? Any ideas how to fix this?
I run with multiple Python versions and thus multiple pip versions as well.
Everytime, however, you update pip, you'll replace the standard pip command with the version you updated. So even pip3 install --upgrade pip will put a /usr/local/bin/pip in your system, messing up the Python 2 version.
Instead, I run pip as an (executable) module:
python3 -m pip search <package>
or
python2 -m pip search <package>
or even
python3.5 -m pip search <package>
This guarantees that your pip version always matches the Python version you want to use it for. It's somewhat longer to type, but I prefer the expliciteness of it (which, I guess, follows the Zen of Python).
Note that updating pip:
python3.5 -m pip install --upgrade pip
will still install a Python 3.5 version in /usr/local/bin/pip, but I'm simply ignoring that. Just beware of (shell) scripts that execute pip directly.
Find absolute path to Python you'd like to use:
which python
Open your default pip executable script:
vi $(which pip)
You will see a shebang line at the top which may point to wrong Python (i had that once too).
Point to the Python you want (see step 1), e.g.:
#!/usr/local/bin/python3.7
Try setting aliases by running the following commands in Terminal,
alias pip="/usr/local/bin/pip"
alias pip2="/usr/local/bin/pip"
alias pip3="/usr/local/bin/pip3"
If this solves your problem then you need to add the aliases in your bash profile.
Look How do I create a Bash alias? for more info.
Alternatively, you have to reinstall pip using python2 get-pip.py first and then python3 get-pip.py get-pip.py can be downloaded here https://bootstrap.pypa.io/get-pip.py
I had exactly the same problem!
I reinstall python2 by brew brew reinstall python#2
after reinstall, pip install packagename works!
None of these worked for me so what I did was navigate to
C:\Users(User)\AppData\Local\Programs\Python\
and deleted all the old python versions I wasn't using. (Worked)
I have installed a python package with python setup.py install.
How do I uninstall it?
Note: Avoid using python setup.py install use pip install .
You need to remove all files manually, and also undo any other stuff that installation did manually.
If you don't know the list of all files, you can reinstall it with the --record option, and take a look at the list this produces.
To record a list of installed files, you can use:
python setup.py install --record files.txt
Once you want to uninstall you can use xargs to do the removal:
xargs rm -rf < files.txt
Or if you're running Windows, use Powershell:
Get-Content files.txt | ForEach-Object {Remove-Item $_ -Recurse -Force}
Then delete also the containing directory, e.g. /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/my_module-0.1.egg/ on macOS. It has no files, but Python will still import an empty module:
>>> import my_module
>>> my_module.__file__
None
Once deleted, Python shows:
>>> import my_module
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'my_module'
For me, the following mostly works:
have pip installed, e.g.:
$ easy_install pip
Check, how is your installed package named from pip point of view:
$ pip freeze
This shall list names of all packages, you have installed (and which were detected by pip).
The name can be sometime long, then use just the name of the package being shown at the and after #egg=. You can also in most cases ignore the version part (whatever follows == or -).
Then uninstall the package:
$ pip uninstall package.name.you.have.found
If it asks for confirmation about removing the package, then you are lucky guy and it will be removed.
pip shall detect all packages, which were installed by pip. It shall also detect most of the packages installed via easy_install or setup.py, but this may in some rare cases fail.
Here is real sample from my local test with package named ttr.rdstmc on MS Windows.
$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev
$ python setup.py develop
.....
.....
Finished processing dependencies for ttr.rdstmc==0.0.1dev
$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
-e hg+https://vlcinsky#bitbucket.org/vlcinsky/ttr.rdstmc#d61a9922920c508862602f7f39e496f7b99315f0#egg=ttr.rdstmc-dev
ttr.utcutils==0.1.1dev
$ pip uninstall ttr.rdstmc
Uninstalling ttr.rdstmc:
c:\python27\lib\site-packages\ttr.rdstmc.egg-link
Proceed (y/n)? y
Successfully uninstalled ttr.rdstmc
$ pip freeze |grep ttr
ttr.aws.s3==0.1.1dev
ttr.aws.utils.s3==0.3.0
ttr.utcutils==0.1.1dev
Edit 2015-05-20
All what is written above still applies, anyway, there are small modifications available now.
Install pip in python 2.7.9 and python 3.4
Recent python versions come with a package ensurepip allowing to install pip even when being offline:
$ python -m ensurepip --upgrade
On some systems (like Debian Jessie) this is not available (to prevent breaking system python installation).
Using grep or find
Examples above assume, you have grep installed. I had (at the time I had MS Windows on my machine) installed set of linux utilities (incl. grep). Alternatively, use native MS Windows find or simply ignore that filtering and find the name in a bit longer list of detected python packages.
The #1 answer has problems:
Won't work on mac.
If a file is installed which includes spaces or other special
characters, the xargs command will fail, and delete any
files/directories which matched the individual words.
the -r in rm -rf is unnecessary and at worst could delete things you
don't want to.
Instead, for unix-like:
sudo python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then:
tr '\n' '\0' < files.txt | xargs -0 sudo rm -f --
And for windows:
python setup.py bdist_wininst
dist/foo-1.0.win32.exe
There are also unsolvable problems with uninstalling setup.py install which won't bother you in a typical case. For a more complete answer, see this wiki page:
https://ofswiki.org/wiki/Uninstalling_setup.py_install
First record the files you have installed. You can repeat this command, even if you have previously run setup.py install:
python setup.py install --record files.txt
When you want to uninstall you can just:
sudo rm $(cat files.txt)
This works because the rm command takes a whitespace-seperated list of files to delete and your installation record is just such a list.
Now python gives you the choice to install pip during the installation (I am on Windows, and at least python does so for Windows!). Considering you had chosen to install pip during installation of python (you don't actually have to choose because it is default), pip is already installed for you. Then, type in pip in command prompt, you should see a help come up. You can find necessary usage instructions there. E.g. pip list shows you the list of installed packages. You can use
pip uninstall package_name
to uninstall any package that you don't want anymore. Read more here (pip documentation).
Not exactly answering the question, but something that helps me every day:
Install your packages with
pip install .
This puts the package in $HOME/.local. Uninstall with
pip uninstall <package_name>
The lazy way: simply uninstall from the Windows installation menu (if you're using Windows), or from the rpm command, provided you first re-install it after creating a distribution package.
For example,
python setup.py bdist_wininst
dist/foo-1.0.win32.exe
("foo" being an example of course).
Go to your python package directory and remove your .egg file,
e.g.:
In python 2.5(ubuntu): /usr/lib/python2.5/site-packages/
In python 2.6(ubuntu): /usr/local/lib/python2.6/dist-packages/
Probably you can do this as an alternative :-
1) Get the python version -
[linux machine]# python
Python 2.4.3 (#1, Jun 18 2012, 14:38:55)
-> The above command gives you the current python Version which is 2.4.3
2) Get the installation directory of python -
[linux machine]# whereis python
python: /usr/bin/python /usr/bin/python2.4 /usr/lib/python2.4 /usr/local/bin/python2.5 /usr/include/python2.4 /usr/share/man/man1/python.1.gz
-> From above command you can get the installation directory which is - /usr/lib/python2.4/site-packages
3) From here you can remove the packages and python egg files
[linux machine]# cd /usr/lib/python2.4/site-packages
[linux machine]# rm -rf paramiko-1.12.0-py2.4.egg paramiko-1.7.7.1-py2.4.egg paramiko-1.9.0-py2.4.egg
This worked for me.. And i was able to uninstall package which was troubling me :)
I think you can open the setup.py, locate the package name, and then ask pip to uninstall it.
Assuming the name is available in a 'METADATA' variable:
pip uninstall $(python -c "from setup import METADATA; print METADATA['name']")
At {virtualenv}/lib/python2.7/site-packages/ (if not using virtualenv then {system_dir}/lib/python2.7/dist-packages/)
Remove the egg file (e.g. distribute-0.6.34-py2.7.egg)
If there is any from file easy-install.pth, remove the corresponding line (it should be a path to the source directory or of an egg file).
Extending on what Martin said, recording the install output and a little bash scripting does the trick quite nicely. Here's what I do...
for i in $(less install.record);
sudo rm $i;
done;
And presto. Uninstalled.
If you still have files that are supposed to be deleted after re-installing a package, make sure the folder build is also deleted. Therefore, assuming that pkg is the package you want to delete:
rm -r $(python3 -c "import pkg; print(pkg.__path__[0] + '*' )")
rm -rf build
Obove work out for python3 and delete the package and its *.egg-info file
Install from local
python setup.py install
Uninstall from local
pip uninstall mypackage
It might be better to remove related files by using bash to read commands, like the following:
sudo python setup.py install --record files.txt
sudo bash -c "cat files.txt | xargs rm -rf"
I had run "python setup.py install" at some point in the past accidentally in my global environment, and had much difficulty uninstalling. These solutions didn't help. "pip uninstall " didn't work with "Can't uninstall 'splunk-appinspect'. No files were found to uninstall." "sudo pip uninstall " didn't work "Cannot uninstall requirement splunk-appinspect, not installed". I tried uninstalling pip, deleting the pip cache, searching my hard drive for the package, etc...
"pip show " eventually led me to the solution, the "Location:" was pointing to a directory, and renaming that directory caused the packaged to be removed from pip's list. I renamed the directory back, and it didn't reappear in pip's list, and now I can reinstall my package in a virtualenv.
I had run python setup.py install once in my PyCharm, it installs all the packages into my conda base environment. Later when I want to remove all these packages, pip uninstall does not work. I had to delete them from /anaconda3/lib/python3.7/site-packages manually :(
So I don't see the reason why they use setup.py instead of writing requirements.txt file. The requirement file can be used to install packages in virtual environment and won't mess with system python packages.
I have a develop egg link set up with python setup.py develop under a conda environment and with pip uninstall <packagename> the egg link is removed. At least in this scenario, pip uninstall is one way to do this.