How to install pip3 for a specific python version - python-3.x

I have python3.7 installed but also python3.4. For example:
$ python3
Python 3.4.3 (default, Nov 12 2018, 22:25:49)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
And:
$ python3.7
Python 3.7.0 (default, Jun 28 2018, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
How can I install packages to python3.7 ? Any pip3 command I use goes to python3.4 and I'm not sure how to install anything for python3.7. Any ideas? Even running something like this doesn't work:
$ python3.7 -m ensurepip --upgrade
/usr/bin/python3.7: No module named ensurepip
Or:
$ sudo python3.7 -m pip install PyMySQL
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

I don't know whether this may be an appropriate solution for you. But this is what I generally follow.
Just install Anaconda in your system and create different environments according to your needs.
For your case create two different environments one for Python 3.4.3 and another for Python 3.7 using the following command
conda create --name py34 python=3.4.3 and
conda create --name py37 python=3.7
//This lines will create two new environments named py34 and py37
You then install libraries according to your needs in the respective environment. Now you can work into each environment without interfering with the libraries of the other environment.
To use anaconda kindly follow Anaconda cheatsheet. You will get everything that you need.
Hope this will help you.

This might help : It addresses the same issue as yours. In short, try
python3.7 -m pip install pip
Here's a reference documentation

Related

Need help in resolving issue with two versions of python available in my Macbook

I recently bought macbook and i'm new to everything in this OS. Followed some tutorials to setup the machine towards programming and development. In that way, i had installed python(3.9) through Homebrew, later while checking path in both brew and terminal, both are pointing out to python 2.7.16, Then i realized Mac OS already had its own installation with 2.7.16. Now i am going through multiple suggestion on web, that how to overcome this and to make a single version as default. I found the below commands to link brew's version(3.9.15) with system's version(2.7.16). Copied from another post.
[[ Here is what was confusing me and how I solved it.
$ which python
/usr/bin/python
$ which python3
/usr/local/bin/python3
$ ls /usr/local/bin/python
ls: /usr/local/bin/python: No such file or directory
So notice I didn't have a HomeBrew installation of python2.7, but did have the python3 installation. The version under /usr/bin/python is using the system default. You can tell based on the module search path:
$ /usr/bin/python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
`enter code here`Type "help", "copyright", "credits" or "license" for
more information.
>>> import sys
>>> sys.path
['', '/Library/Python/2.7/...
Notice the '/Library/Python'... that's Mac OS's version of python. But I want to stay strictly on a user installed version (i.e. HomeBrew).
So here's what I did to fix this:
$ brew install python
...
Warning: python 2.7.13 is already installed, it's just not linked.
You can use `brew link python` to link this version.
$ brew link --overwrite python
$ which python
/usr/local/bin/python
$ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/Cellar/python/2.7.13...
Its no longer /Library/.. but /usr/local.
Now its finding all of my pip installed modules! Problem solved! ]]
The above Steps are actually dealing the merging of similar version ~ 2.7 which is of Python2.
But in my machine, i had installed Python3 and it has Python2 earlier.
Here is my question.
Do i have to update the System's version first to Python3 and then link it with Brew's version(3.9.15) by following the above commands or Any suggestions please??
Do i have to update the System's version first to Python3 and then link it with Brew's version(3.9.15)
python2 and python3 are incompatible software. You shouldn't try to "update" that version to python3. Because if you do that existing software might stop working, as it probably depends on python2. Your best course of action would be to use python3 version from brew explicitly, python2 is in deprecation mode anyway. (I use alias like alias py3=python3, so I can invoke it with py3 instead of writing python3)
As an aside - you should set up your projects/programs using virtualenv/venv; that will allow to not pollute your system installation. You can even share that with another computer by extracting project dependencies in requirements.txt.

Virtualenv created using a Pipenv environment always has access to site-packages

This might be a bug, but: if I create a virtualenv while using a Pipenv environment that virtualenv always has access to site packages for that Pipenv environment.
$ pipenv install numpy
Creating a virtualenv for this project…
...
$ pipenv run python -m venv venv # Default behaviour is not to allow access to site-packages
$ source venv/bin/activate
(venv) $ python
Python 3.7.2 (default, May 1 2019, 12:27:28)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
Why is this happening?
Can I avoid it?

python3.6 help command dumping core when we try help(tensorflow)

I am running Ubuntu Linux 18.04 on Virtual box,
I have installed tensorflow properly in venv and import works fine and also
I could run some sample programs with tensorflow, but when i try help(tf) python prompt as show below in the logs, I am hitting coredump,
`(venv) shiv#shiv-vbox:~/TF$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> x=0
>>> help(x)
>>> help(tf)
Segmentation fault (core dumped)`
Is something wrong with my installation? i tried multiple times to install to confirm some issue with install but all the time I am getting cordump when I do help(tf), any inputs on this would be helpful.
-Thank you
update
I followed following steps to install
shiv#shiv-vbox:~/TF$ sudo virtualenv --system-site-packages -p python3 ./venv
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/shiv/TF/venv/bin/python3
Also creating executable in /home/shiv/TF/venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
shiv#shiv-vbox:~/TF$ source ./venv/bin/activate
(venv) shiv#shiv-vbox:~/TF$
(venv) shiv#shiv-vbox:~/TF$ ls
Tflow venv
(venv) shiv#shiv-vbox:~/TF$ pip install --upgrade pip
Requirement already up-to-date: pip in ./venv/lib/python3.6/site-packages (18.1)
(venv) shiv#shiv-vbox:~/TF$ pip install tensorflow

MacOS Python 3.7 virtualenv fails?

My system is running MacOS and Homebrew and it recently updated to Python 3.7.
Now, just creating a new virtualenv and trying to use it fails.
FYI, I don't actually need Python 3.7. I didn't upgrade on purpose. I'd prefer the latest stable, supported version, but of course, I want the basics working.
➜ rm -rf ~/.virtualenvs/test
➜ python3 -m venv ~/.virtualenvs/test
➜ vex --path ~/.virtualenvs/test python
zsh: /usr/local/bin/vex: bad interpreter: /usr/local/opt/python/bin/python3.6: no such file or directory
➜ python3
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
/usr/local/bin/vex file has this as the first line: #!/usr/local/opt/python/bin/python3.6; it's called shebang and it points operating system to the interpreter to run the script. You've uninstalled python3.6 so OS cannot find said interpreter. You need to reinstall vex with python3.7.

getting error 'No module named pip3' in spite of pip3 being present

I'm on ubuntu 14.04. Python 3.4 was present already, I additionally installed python 3.6.
Python 3.6 seemingly runs fine:
...:/usr/bin$ python3.6
Python 3.6.3 (default, Oct 6 2017, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
pip3 also runs fine, but for python 3.6.4 (as expected):
...:/usr/bin$ pip3 -V
pip 9.0.1 from /usr/local/lib/python3.4/dist-packages (python 3.4)
So I tried running pip3 under python 3.6, but no luck:
...:/usr/bin$ python3.6 -m pip3 -V
/usr/bin/python3.6: No module named pip3
When searching I found a couple of suggestioons aroundthat error message, but they were all about pip3 not working at all, which is not my problem.
What am I getting wrong?

Resources