Install Gensim in python3 - python

I have two versions of python: python2, python3.
When I install gensim it goes to python2
I install it with the following comand
sudo pip3 install --upgrade gensim
how can I install it in python3?

You can install it in python3 with the following command:
sudo python3 -m pip install --upgrade gensim

I suggest using a virtualenv with only python3 in it. You can create it using
virtualenv -p /usr/bin/python3 myenv
then activate it using source command.
source myenv/bin/activate
now you can install using pip install gensim that will install it to the python3 specific to that virtual environment.

Related

-bash: pip: command not found, but with `python3 -m pip --version` shows the latest pip version

I get -bash: pip: command not found when I try to use pip -V or any other command with pip / pip3, I used to easily install something using pip3 install .., now pip doesn't work for some reason, BUT if I will write python3 -m pip --version I will get pip 21.1.3 from /Users/work/Library/Python/3.9/lib/python/site-packages/pip (python 3.9) , this seems to be the latest version at the moment and I can no longer install using the pip3 install .. command, using python3 -m pip, what could be the problem? I want to use pip3 like before
Thanks to all!
It seems to me that you need update Path in system variables.
Just add "Python_location"\Scripts\ (for example: c:\Python3\Scripts) to Path

How to install pip library in ec2-instance virtual environment using user data?

enter image description hereI am try to install pip libraries in ec2-instances virtual environment using user data.
But while I am trying that I will create at instance level but not at virtual environment level.
What I need exactly is will I am creating ec2-instance on configuration level I want to define that to create pip libraries at virtual environment level.
#!/usr/bin/env bash
sudo yum update
sudo yum install python3 pip3 -y
sudo pip3 install --upgrade pip
pip install --upgrade pip
python3 -m venv /home/ec2-user/vertual-Environment
pip install django
pip install djangorestframework
pip install pillow
You have to source your python env envrionment.
Example (I have verified now the code on Amazon Linux 2):
#!/usr/bin/env bash
sudo yum update -y
sudo yum install python3 python3-pip -y
sudo pip3 install --upgrade pip
pip install --upgrade pip
python3 -m venv /home/ec2-user/vertual-Environment
# source your new python env
source /home/ec2-user/vertual-Environment/bin/activate
pip install django
pip install djangorestframework
pip install pillow
Using user data, your should install your dependencies this way :
python3 -m venv /home/ec2-user/vertual-Environment
/home/ec2-user/vertual-Environment/bin/pip install django
/home/ec2-user/vertual-Environment/bin/pip install djangorestframework
/home/ec2-user/vertual-Environment/bin/pip install pillow
When using userdata, your script are executed independently, regardless of what have been done in previous executions.

Installing pip to import modules

I am attempting to install matplotlib and scipy to python, and using pip to do so. However when I attempted to install scipy with pip install scipy --myuser I received the message:
invalid requirement '--myuser'
Previously I had installed numpy using pip with
python get-pip.py —myuser
and
pip install numpy —myuser
This worked fine, so I am unsure what the problem is here.
This is frustrating as I would like to use python from the terminal rather than from my Windows desktop.
If you want to install to user try the below mentioned command:
pip install --user scipy
Here is the help from pip command:
pip install --help
--user Install to the Python user install directory for
your platform. Typically ~/.local/, or
%APPDATA%\Python on Windows. (See the Python
documentation for site.USER_BASE for full
details.)
You should be able to install it without the use of the --myuser argument.
sudo python3 -m pip install scipy
sudo python3 -m pip install matplotlib
or all in one
sudo python3 -m pip install scipy matplotlib
Try this:
sudo python3 -m pip install scipy matplotlib

How to install mesa (python package) for use in python 3

I have installed mesa via:
$ pip install mesa
but it is automatically installing it into
/Users/MyName/Documents/User/lib/python2.7/site-packages/mesa/~
which means that when I try to run it with a Python 3 kernel, it can't find the module and I receive the error
ModuleNotFoundError: No module named 'mesa'
Could someone help me out? I'm assuming the problem is that it is automatically installed into the python 2.7 directory - how can i change this?
Thanks
To install packages for Python3 while exists Python2,
try this
python3 -m pip install xxx
or this
sudo apt install pip3
pip3 install xxx
You should use pip3 instead of pip:
pip3 install mesa
If you don't have pip3 install it using:
sudo apt-get update
sudo apt-get -y install python3-pip
If it doesn't work you can do it manually using curl:
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py
You can also execute it straight from python3:
python3 -m pip install mesa
It is always a good practice to set pip command to be equivalent to your python command. i.e, if python points to python3, you better change pip to point to pip3. Add alias pip='pip3' to your ~/.bash_profile file.

How to upgrade pip3?

I want to use python3.5 for development, but many times when I install the module for python 3.5, it always fails. The terminal tells me that a higher version is available, but it doesn't work when I upgrade it.
You are using pip3 to install flask-script which is associated with python 3.5. However, you are trying to upgrade pip associated with the python 2.7, try running pip3 install --upgrade pip.
It might be a good idea to take some time and read about virtual environments in Python. It isn't a best practice to install all of your packages to the base python installation. This would be a good start: http://docs.python-guide.org/en/latest/dev/virtualenvs/
To upgrade your pip3, try running:
sudo -H pip3 install --upgrade pip
Your pip may move from /bin to /usr/local/bin
To upgrade pip as well, you can follow it by:
sudo -H pip2 install --upgrade pip
Try this command:
pip3 install --upgrade setuptools pip
First decide which pip you want to upgrade, i.e. just pip or pip3.
Mostly it'll be pip3 because pip is used by the system, so I won't recommend upgrading pip.
The difference between pip and pip3 is that
NOTE: I'm referring to PIP that is at the BEGINNING of the command
line.
pip is used by python version 2, i.e. python2
and
pip3 is used by python version 3, i.e. python3
For upgrading pip3: # This will upgrade python3 pip.
pip3 install --upgrade pip
For upgrading pip: # This will upgrade python2 pip.
pip install --upgrade pip
This will upgrade your existing pip to the latest version.
The Problem
You use pip (the Python 2 one). Now you want to upgrade pip (the Python 3 one). After that, pip is the Python 3 one.
The solution
Use pip2 and pip3. This way it is explicit.
If you want to use pip, just check where it is (which pip) and change the link. For example:
$ which pip
/usr/local/bin/pip
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
$ which pip2
/usr/local/bin/pip2
$ sudo rm /usr/local/bin/pip
$ sudo ln -s /usr/local/bin/pip2 /usr/local/bin/pip
$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
for Python 3:
python3 -m pip install --upgrade pip
for Python 2:
python2 -m pip install --upgrade pip
What worked for me was the following command:
python -m pip install --upgrade pip
pip3 install --upgrade pip worked for me
In Ubuntu 18.04, below are the steps that I followed.
python3 -m pip install --upgrade pip
For some reason you will be getting an error, and that be fixed by making bash forget the wrongly referenced locations using the following command.
hash -r pip
If you have 2 versions of Python (eg: 2.7.x and 3.6), you need do:
add the path of 2.x to system PATH
add the path of 3.x to system PATH
pip3 install --upgrade pip setuptools wheel
for example, in my .zshrc file:
export PATH=/usr/local/Cellar/python#2/2.7.15/bin:/usr/local/Cellar/python/3.6.5/bin:$PATH
You can exec command pip --version and pip3 --version check the pip from the special version. Because if don't add Python path to $PATH, and exec pip3 install --upgrade pip setuptools wheel, your pip will be changed to pip from python3, but the pip should from python2.x
This worked for me (mac)
sudo curl https://bootstrap.pypa.io/get-pip.py | python
If you try to run
sudo -H pip3 install --upgrade pip3
you will get the following error:
WARNING: You are using pip version 19.2.3, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
but if you upgrade using the suggested command:
pip install --upgrade pip
then, the legacy pip will be upgraded, so what I did is the following:
which pip3
and I located my pip3 installation (just in case the following command wouldn't upgrade the legacy pip. Then i changed to that directory and upgraded pip3 using the following commands: (your directory could be different)
cd /Library/Frameworks/Python.framework/Versions/3.8/bin
sudo -H pip3 install --upgrade pip
after this:
pip --version
will still show the legacy version, while
pip3 --version
will show pip 21.0.1

Categories