MacOS Python 3.7 virtualenv fails? - python-3.x

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.

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.

How do I remove python 3.8 when i have both python 3.7 and 3.8 installed on MacOS?

I have a really messy python installation on my mac, need some help.
I installed python3 with Homebrew and it showed that
python 3.7.8 is already installed and up-to-date
But when I run python3 on my terminal, i see,
Python 3.8.3 (default, May 27 2020, 20:53:40)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
And now i cant install any modules with pip3, it shows,
File "/usr/local/opt/python#3.8/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
ModuleNotFoundError: No module named 'pkg_resources'
I would like to remove python 3.8 completely and use 3.7 instead, what should I do?
solution
In the link there is solution about deleting 2.8. I guess deleting python versions does not change version to version. Check that link.

How to install pip3 for a specific python version

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

How to have python3.6 alongside python3.7 windows 10

I'm trying to install tensorflow onto a Windows PC with Python3.7. However, I'm had errors. From what I can gather this is happening because tensorflow doesn't yet support Python3.7. As a workaround I want to install Python3.6 alongside 3.7 and then install tensorflow to that version. However, I'm new to Windows and
when I call for Python in the terminal I now have
C:\Users\antoi>python
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
How can I have 3.7 as well as we would have been able on Ubuntu ?
You can just install python 3.6, add it's binary path to the system path and call it as python3.6 (actually the same way it works in ubuntu). You can also explicitly call it with its full path: C:\Program Files\Python3.6\bin\python3.6.exe -m pip install tensorflow.

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