pip: How to deal with different python versions to install Flask? - python

I have different versions of Python installed on my Ubuntu machine (2.7.11, 2.7.12, 3.5). I would like to install Flask on the 2.7.12 as it used by Apache.
I have three pip{version} in my PATH which are: pip, pip2, and pip2.7. How do I know which one is for which python version.
I have already read Here but it didn't help my case as I need to differentiate between minor version number 2.7.11 and 2.7.12.
One thing is that I tried pip{version} install Flask for all three pips but the 2.7.12 still can't import Flask.
Any help is much appreciate it.
Thanks

You should always create virtualenvs for your projects. You can create one like
virtualenv -p <path/to/python2.7.12> <path/to/new/virtualenv/>
inside that virtualenv pip and python will always select the right interpreter and path.

You can find it out by trying to run this: pip --version. Output will be something like this: pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7). This way we can see that it is for python2.7 in my case.

Related

Updating Python3 and Pip3 on Mac

I have two versions of python3 installed on my computer. They are located here:
/usr/local/bin/python3
/usr/bin/python3
I have set my PATH variable to use the first version. Running "which python3" routes to this version: /usr/local/bin/python3 -- this is what I want.
Unfortunately, pip3, and yet another version of Python, are installed in a different location (I think the version that comes pre-installed with mac). When I run "pip3 --version" I get the below:
pip 20.1.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
Shouldn't these match? Is there a way to make sure python3 uses the pip3 version via /usr/local/bin/pip3? Do I just need to change / add it to my path somehow?
Another option is to uninstall everything with homebrew (what I used to originally install python3), and then reinstall. However, apparently, per my co-worker, we need to stay on python3.7. I'm worried if I reinstall python3, it will default to 3.8 or higher.
Please help!
There are a few things that I have found increase the chances of success here:
don't mess with the Mac-installed default Python
don't use homebrew to install Python
use pyenv to install and manage Python versions
Here's a useful write-up on The right and wrong way to set Python 3 as default on a Mac.

Error when installing Tensorflow - Python 3.8

I'm new to programming and following a course where I must install Tensorflow. The issue is that I'm using Python 3.8 which I understand isn't supported by Tensorflow.
I've downloaded Python 3.6 but I don't know how to switch this as my default version of python.
Would it be best to set up a venv using python 3.6 for my program and install Tensorflow in this venv?
Also, I using Windows and Powershell.
Tensorflow is only supported until python 3.7 as of now.
You can check it here: https://www.tensorflow.org/install/pip
But there is a way to install it on Python3.8, just run the below command that will do your job:
python -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl
This command work on mac and windows both, I haven't tested on Linux.
You should always use venv because by default every project on your system will use these same directories to store and retrieve site packages (third party libraries). At first glance, this may not seem like a big deal, and it isn’t really, for system packages (packages that are part of the standard Python library), but it does matter for site packages.
Consider the following scenario where you have two projects: ProjectA and ProjectB, both of which have a dependency on the same library, ProjectC. The problem becomes apparent when we start requiring different versions of ProjectC. Maybe ProjectA needs v1.0.0, while ProjectB requires the newer v2.0.0.
You can also take a look at anaconda, it’s the most populasr data sciencie platform and will be easy for you install tensorflow and jupiter notebook in just 2 clicks. Anaconda
Uninstall all your python versions and use the latest anaconda.
$ conda create --name tensorflow python=3.5
This way you create a virtual environment with python 3.5 which is supported by tensorflow.
So now you can install it.
$ activate tensorflow
(tensorflow) $ pip install tensorflow
it would have been nice if you would have the share the error screenshot
though as per i got the case
tensorflow work in both 3.8 and 3.6 just you have to check that you have 64bit version not 32 bit
you can acess both version from thier respective folder no need to install a venv
If you don't want to use Anaconda or virtualenv, then actually multiple Python versions can live side by side. I use Python38 as my default and Python35 for TensorFlow until they release it for Python38. If you wish to use the "non-default" Python, just invoke with the full path of the python.exe (or create a shortcut/batch file for it). Python then will take care of using the correct Python libs for that version.
Worked on Python 3.8.2 (default, Mar 05 2020, 18:58:42) [GCC] on linux
pip3 install --upgrade tf-nightly
Python Versions 3.5 - 3.8 are supported now.
You can verify on this page:
https://www.tensorflow.org/install/pip

Should Which Pip and Which Python Return the Same Directory? Zeppelin Configuration On Unix RHEL

This is probably a really dumb question but I am stuck and wasting too much time on this so I would SO appreciate any help.
I am using a RHEL 7 box and installed Apache Zeppelin on it. Everything works except for the life of me I can't import Python packages such as Pandas.
I realized I didn't have PIP so I installed it with these steps: https://pip.pypa.io/en/stable/installing/ (notice I had to use the "--user" argument for the command "python get-pip.py").
Finally, I did "pip install pandas --user" which worked perfectly. I then go into my Zeppelin notebook and I cannot import pandas, even after restarting the Python interpreter.
I did some research and I think the problem is that "which python" and "which pip" are installed in different directories as the former results in "/usr/bin/python" while the latter in "~/.local/bin/pip".
So I suspect the packages installed with pip are basically getting loaded into a different version of python? If it helps, when I do "whereis python" I get 5 different results such as "/usr/bin/python" and "/usr/bin/python2.7" etc.
First thing to understand is: Python packages aren't installed globally, every installed Python has its own set of packages. BTW, pip being a Python package with a script is also not global. If you have a few different pythons you need different pips for them. I don't know Apache Zeppelin so I cannot guess if it uses the system Python (/usr/bin/python) or has its own Python; in the latter case you need to install pip specifically for Zeppelin so its pip install packages available for Zeppelin.
To investigate to what Python pip installs packages you need to find out under what python it runs. Start with shebang:
head -1 `which pip`
The command will prints something like ~/.local/bin/python. If it's not the version of Python you need to install packages for you need to install a different pip using that Python.
The most complex case would be if the shebang is PATH-dependent, something like #!/usr/bin/env python. In that case pip runs Python that you can find with which python.
PS. AFAIK the simplest way to install pip at RedHat is dnf install python-pip.
phd's answer was very helpful but I found that it was just a matter of using the root account to install the python packages. Then my Zeppelin was able to see any packages.

Pip error: Fatal error in launcher: Unable to create process using '"'

I've seen many threads about this, and have tried all options except for completely wiping Python off of my machine and re-downloading everything...
I'm using a Windows 10, 64-bit machine, and had already downloaded Python2.7. Commands like 'C:\>pip install seaborn' were not an issue.
I recently downloaded Python3.6, and now my pip will not work - it returns the error in the title.
I have added C:\Python27, C:\Python36, C:\Python27\Scripts, C:\Python36\Scripts to my Path, and still it won't work.
If I type in the command C:\>python27 -m pip install seaborn, however, the pip works. I am really confused why I can no longer just type in pip install and have it work.
Thanks in advance!
You have two versions of Python added to path. To differentiate between 2.7 and 3.6 you have to tell it which version you want otherwise each pip conflicts with the other (it does not know what to install and where) in other words you type pip you could either mean for Python 2 or for Python 3.
Do not rename pip it will break your system (you should not need to rename). Instead use those already provided..
Your system should have these already:
pip is universal. Best for one installation.
pip3 for Python 3. Best to distinguish between Python 2 and 3
pip3.6 to distinguish between different Python 3 installations.
The same goes for Python 2 installation.
pip, pip2 and pip2.7.
You need to use either pip3 (or pip2) or pip3.6 (or pip2.7) to install in future. This will allow the different versions to be recognised:
For Python 2:
pip2 install seaborn
For Python 3:
pip3 install seaborn
You should also now use shebang lines as well now (if you are not already) to distinguish between versions.
the issue is the ambiguity between the two pip that you've mentioned in the Environments. As you mentioned the issue only started occurring when you installed python3 on the same system where python2 was installed and both have pip and hence when you fire up pip in your cmd, Windows System isn't able to pick one out of the two.
Why does your C:>python27 -m pip install seaborn work?
Well it's quite simple, since you've mentioned the python27 there, windows knows exactly which pip you're talking about.
How to fix it?
see the edits for this section. (I tried this, it didn't work) Removed it from the final answer to avoid confusion.
Alternatively, what you can do is,
rename your python.exe for python 3 to python3. Don't forget to put it inside your PATH environment. Just use python for python 2, python3 for python 3.
Their pip are separated, pip for python 2. pip3 for python 3.
Now, run and see the below commands behave:
# will return the default version of pip
pip --version
# will use the Python 2 version of pip
pip2 --version
# will use the Python 3 version of pip
pip3 --version
Okay so I finally worked it out...
I uninstalled Python3.6 and deleted all relevant folders.
I then went to Control Panel>Programs>Progams and Features and repaired my Python2.7 program. pip works now (I think it got messed up since I tried to rename the universal pip.exe file -> don't do that!!).
After re-downloading Python3.6, I put my universal pip.exe download from Python3 in a different directory so the Path would not get it confused. I now have Paths for both pip2 and pip3 and all is okay.
Thanks for your help!
This is how I solved this issue on my end: (short answer, remove this folder C:\Python27)
Problem: I installed python 3, after uninstalling python 2.7. The issue here is that pip remains behind even after you uninstall python 2.7.
Solution:
1. Uninstall python 3 (if you have it installed).
2. Just in case, I would uninstall python 2.7.
3. This is the key: go to C:\Python27 ... and delete the entire directory (which also contains pip).
This solution is good for those that are fine with ONLY running Python 3 on their machines (which was my case).

Which version of Pip to use with my Python installs?

Being new to Python, I'd love to clear up a few points that I couldn't get from reading various articles and tutorials.
After using Homebrew to install Python3, I noticed that it had installed both Python3 and Python3.4. I was also a little surprised that there are now three versions of pip on my machine too; pip, pip3 and pip3.4.
I created a new virtualenv and told it to use Python3, using the following command:
virtualenv -p /usr/local/bin/python3 mysite
I was also surprised that the version of Python that it installed in my VM was 3.4.
Is it safe to have these multiple version of Python and Pip hanging around on my machine?
Am I right to assume that I should take extra care to use the matching version of pip with Python, for example, pip3.4 with Python3.4?
Yes, it is safe. Python uses this naming like python3.4, python3.5 etc to differentiate between releases. python3 is a symbolic link to the current python3.x version. Pip follows the same convention.
If you're using python3.4 explicitly, you should be using pip3.4 specifically as well. Otherwise, just use python3 and pip3. For Python 2, you can simply use python (which, unless you installed the Homebrew version as well), will be the system Python), and ditto for pip. python2.7 and pip2.7 may also work.
In general, to find out which Python version goes with which pip you're using, try:
pip --version
and you'll see the Python included in the result.
No need to worried about if you have multiple version of Python and Pip installed. just check your version by writing in terminal :
$ brew info python
or to check the version of pip write in terminal :
$ brew info pip
and make sure you have updated your both pip and python version (write in terminal $ brew upgrade pip/python)
and other way to install python is go to https://www.python.org/downloads/ and choose as your requirement, there is two version available 2.7.9 & 3.4.3 ,
after installing python write in terminal $ python -V to check its version :) Hope it will help :)

Categories

Resources