I used easy_install to install nose on my Mac (OS Mavericks). It works fine with the default python 2.7 installation.
If I run nosetests on a module using python 3, it fails to find the imports. What do I need to know and do, to use nose for python 3 as well?
The best way to handle installation (and removal) of third-party packages is to use pip. First, download get-pip.py and save it someplace. Navigate to that folder in Terminal and enter
sudo python3 get-pip.py
to install it for Python 3. I'd recommend running
sudo python get-pip.py
as well to install it for Python 2, as easy_install is deprecated.
Once you have pip installed, you should have access to pip3 or pip-3.3 - check the installation directory to see exactly which scripts were installed. Assuming you have the command pip3, you can now run
sudo pip3 install nose
and it will install nose and any dependencies in your Python 3 site-packages folder, as well as a nosetests executable in your Python installation's bin folder.
These are the steps that I found to work. Thanks, for the parts contributed by MattDMo.
# use python3 to unstall pip3
sudo python3 get-pip.py
which python3
# ls -l on the result of which to find the target of the link
# Using the path to the target (directory), set up links to pip3, pip3.3
ls -l /Library/Frameworks/Python.framework/Versions/3.3/bin/
ln -s /Library/Frameworks/Python.framework/Versions/3.3/bin/pip3 /usr/local/bin/pip3
ln -s /Library/Frameworks/Python.framework/Versions/3.3/bin/pip3.3 /usr/local/bin/pip3.3
# install nose for python3
# and set a link to the installation
sudo pip3 install nose
ln -s /Library/Frameworks/Python.framework/Versions/3.3/bin/nosetests-3.3 /usr/local/bin/nosetests-3.3
Related
I am trying to use these steps with bitbucket CI to deploy an application:
script:
- apt-get update
- apt-get install -y python-dev
- curl -O https://bootstrap.pypa.io/get-pip.py
- python get-pip.py
... and a few more steps
However, the python get-pip.py step fails with this error:
Traceback (most recent call last):
File "get-pip.py", line 24226, in <module>
main()
File "get-pip.py", line 199, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
from pip._internal.cli.main import main as pip_entry_point
File "/tmp/tmpUgc5ng/pip.zip/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
Why isn't it working now? Does it depend on the operating system?
For the equivalent issue with upgrading pip in old Python installations, see Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}").
pip 21.0 dropped support for Python 2 and 3.5. The later versions require Python 3.6+. The syntax f"" is supported by Python 3.6+.
To install pip for Python 2.7 install it from https://bootstrap.pypa.io/pip/2.7/ :
- curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
- python get-pip.py
- python -m pip install --upgrade "pip < 21.0"
The last command is to upgrade to the latest supported version.
For Python 2.7 the latest supported is currently pip 20.3.4.
For Python 3.6 install from https://bootstrap.pypa.io/pip/3.6/
For Python 3.5 install from https://bootstrap.pypa.io/pip/3.5/
For Python 3.4 install from https://bootstrap.pypa.io/pip/3.4/
For Python 3.4 the upgrade command is
python -m pip install --upgrade "pip < 19.2"
I solved it by firstly run
python -m pip install --upgrade "pip < 19.2"
and then
python -m pip install --upgrade "pip < 21.0".
It seems reinstall my pip 20.3.4 and the error disappreared!
This worked for me:On Mac:
Install pyenv as well as upgrade your python following the instructions on this here
Then in your terminal, if you run python -V and you still get the old version(system predefined version) showing:
To resolve this:
In your terminal run: alias python=python3
Then in your terminal execute python and you should now see that your system is using the python version you installed-:That is if you followed and completed the steps Here Correctly.
Restart your terminal(close/reopen):
Now you can finally install pip:
Read more about pip instalation steps [here][3]
1:In your terminal execute :$ python -m ensurepip --upgrade
2: Download the script, from https://bootstrap.pypa.io/get-pip.py.
But..**NB**: instead of navigating to the exact link provided,check out the available versions of pip here: pipversions
Select the latest version:
Then select getpip.py link to get the file and save it into your directory on your machine:
cd into the folder where you saved the newly downloaded script and execute:
Then execute:
python get-pip.py
Pip installed successfully:
For me python 3.5 on aws ec2 below worked
curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py
Then
sudo python3.5 get-pip.pyenter image description here
I have also tried all thing but my solution was download old get-pip version and install.
download: curl -O https://bootstrap.pypa.io/2.7/get-pip.py the file get-pip.py
install: python get-pip.py or python2 get-pip.py
enjoy
This is worked on Debian systems.
Edit: A better solution is always to install a Python version that is long supported. If at all you need to work with an older version - only then must one resort to the above workaround.
Uninstall existing pip on your machine
Run this cmd in ubuntu or any linux machine
curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
python3 get-pip.py
It will work
I usually use python 3.7 on my ubuntu but in order to run a brainfuck jupyter notebook (from https://github.com/robbielynch/ibrainfuck) I need to run python3.4. So I installed python3.4 using
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz
tar xzvf Python-3.4.0.tgz
cd python3.4/
./configure
make
sudo make install
which worked well and I can run python3.4 by typing $ python3.4 in the terminal.
Well, now I tried to install pip for python3.4 as follows:
wget https://bootstrap.pypa.io/get-pip.py
sudo python3.4 get-pip.py
And got a RuntimeError: Python 3.5 or later is required error.
Any ideas, how to install pip for python3.4?
Thanks for any advice!
You can type python3.4 -m pip install <SomePackage>. The python documentation has a section about how to install packages when working with multiple installations.
I am trying to run some python script using ssh to log into the google compute engine but all the installed pip modules are not found as I do not have permission to the .cache/pip folder in my user is there a correct way to do this?
You should be running this with the root user.
Also, if you need pip inside your GCP Instance, you can use the following commands:
sudo curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
sudo python get-pip.py
[Source]
Use:
sudo apt-get install python3-pip
sudo runs this command as an administrator
apt-get is the standard package manager used on Debian Linux distributions
python3-pip is the package name for pip3
Once installed, you can install PIP modules with:
pip3 install MODULE_NAME
for example:
pip3 install tensorflow
I'm not entirely sure there is one correct way to do this, but an easy way would be to use the conda python package manager.
The lighter version of it is miniconda. You can get a minimal python installation with pip preinstalled, and virtual environments capability if you need. Assuming you are running on linux and want python 3, you'll have to run
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
and then install conda with
bash Miniconda3-latest-Linux-x86_64.sh
At the end of this process you should have a minimal python installation (that includes pip) and you'll be able to install packages with pip as you are used to.
You might want to install some basic libraries first -
sudo apt-get install bzip2 libxml2-dev
Then install miniconda as given by #teoguso and restart your shell
source ~/.bashrc
You can then use conda or pip to install your packages
I uninstalled pip, and I installed pip3 instead. Now, I want to use pip3 by typing pip only. The reason is I am used to type pip only and every guide uses the pip command, so every time I want to copy and paste commands, I have to modify pip to pip3 which wastes time. When I type pip I have an error which is pip: command not found which means pip command is not taken. Is it possible to make pip points to pip3?
You can use pip3 using the alias pip by adding alias to your .bashrc file.
alias pip=pip3
or by adding a symlink named pip to your $PATH, which points to the pip3 binary.
If there is no ~/.bashrc in your home directory on macOS, inputting
alias pip=pip3
in your ~/.zprofile file has the same effect.
Rather than manually creating your own alias in bash and hoping this doesn't conflict with anything, most package managers should allow you to register the version you wish to use whilst maintaining dependencies.
For instance on Linux:
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
Or on Mac (MacPorts):
port select --set pip pip3
Solution 1
Check which version pip is pointing to
pip --version
pip 18.0 from /usr/lib/python2.7/site-packages/pip (python 2.7)
If your pip is pointing to pip2, locate where is the pip "binary".
which pip
/usr/bin/pip
This is a simple python script:
cat /usr/bin/pip
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
So just change the shebang from #!/usr/bin/python2 to #!/usr/bin/python3.
Now pip is pointing to pip3.
pip --version
pip 18.0 from /usr/lib/python3.6/site-packages/pip (python 3.6)
Solution 2
Remove /usr/bin/pip make make a symbolic link from the wanted pip version to it instead.
sudo rm /usr/bin/pip
sudo ln -s /usr/bin/pip3.6 /usr/bin/pip
Since you uninstalled pip, this solution assumes you're only going to use pip3.
Open your terminal.
Create a simple link. To do that type:
sudo ln -s /usr/bin/pip3 /usr/bin/pip
Now when you type pip, it will invoke pip3.
Check that it worked by typing pip --version
pip --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
You're all set!
You can install pip after install pip3 by the below command:
pip3 install --upgrade pip
after that:
~ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
You can write pip for pip3 after changing bashrc file in the home directory.
In mac -
Open bashrc file -
vim ~/.bashrc
Add this line at the end of the file -
alias pip="pip3"
Close the file. Don't forget to source this file in the terminal by
source ~/.bashrc
You are good to go. Now, whenever you will use pip in any command. it will be interpreted as pip3
You can check it by running the command -
pip --version
Pip is installed in /usr/bin/. If you don't have pip at all, I would suggest to install pip3 only. Make sure you don't need older version.
You can check available pip versions using following command.
ls /usr/bin/pip*
If you have multiple pip you need to prioritize your pip versions. I had only pip3 so I add it to the first priority. You can use following command and it is done.
sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
You will get output as :
update-alternatives: using /usr/bin/pip3 to provide /usr/bin/pip (pip) in auto mode
Test now:
pip --version
You will get:
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
If you have other version for python2.7, you can use same update command and change last digit 1 to 2. This will make it second priority.
I believe one shouldn't do such a thing. Actually I would argue it's even better to not use the pip, pip3, etc. scripts ever. Instead one should always prefer the more explicit and surefire way of using pip's executable module for one specific Python interpreter:
path/to/pythonX.Y -m pip somecommand
References:
https://snarky.ca/why-you-should-use-python-m-pip/
https://snarky.ca/a-quick-and-dirty-guide-on-how-to-install-packages-for-python/
This can be done by simply creating an alias for the command.
To create an alias just type
$alias new_command="existing_command"
In your case,
$alias pip="pip3"
Although this isn't permanent. OT make it permanent edit your bashrc file
$ vim ~/.bashrc
an to the end of it append the line.
$alias pip="pip3"
It depends on how you manage your python versions (system, brew, pyenv, ...) and which python installation you are currently using.
For example if you use brew then creating a simlink is a good option:
ln -s -f /usr/local/bin/pip3 /usr/local/bin/pip
validate that pip uses the correct version:
which pip
will give you
/usr/local/bin/pip
Copy the pip3 file and rename as pip:
sudo cp /usr/bin/pip3 /usr/bin/pip
pip --version
and
pip3 --version
Works now.
I've read the Pip related responses and still have this question. I'm trying to install pip on Mac OS X 10.6.8. In brief, I run sudo python get-pip.py and get an error that the pip Requirement is already up to date.
But I don't see a 'pip' executable file in the expected directory and can't run pip. Should there be a file called pip in the target pip folder?
More detail:
I'm following directions at: http://docs.python-guide.org/en/latest/starting/install/osx/
1) Used ez_install to install setuptools
2) bashed:
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py $
sudo python get-pip.py
Response is
Requirement already up-to-date: pip in /Library/Python/2.6/site-packages
... I can see a lot of files in this directory
3) I then try to use pip:
/Library/Python/2.6/site-packages/pip install virtualenv
Get back > pip: is a directory
4) I try
/ Library/Python/2.6/site-packages/pip/pip install virtualenv
-bash: /Library/Python/2.6/site-packages/pip/pip: No such file or directory
I look in the above path and can see the pip folder, with numerous files including __main__ and __init__ but no file named pip. Should there be one? if so, how might I clear out the old install and reinstall?
Thanks for any advice!
SL
Here's how I successfully installed pip from the Github repositories on Max OS X 10.9:
Get pip repository:
$ git clone https://github.com/pypa/pip
Perform setup:
$ cd pip
$ sudo python setup.py install
That's it. A test run should give something like:
$ pip -V
pip 1.6.dev1 from /Library/Python/2.7/site-packages/pip-1.6.dev1-py2.7.egg (python 2.7)
And my PATH environment variable is set to:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile