terminal image of version
i am new to python and i just installed python 3.11 from python.org.
now when i am checking the version in TERMINAL, there are two,
python (path: /usr/bin/python3 version-3.9.6)
&&
python3 (path: /usr/local/bin/python3 version-3.11.2)
and the default one is python(3.9.6).
should i change the default one and why are these path different?
my VSCODE is using the new version(3.11.2) by default.
please someone explain.
check out the image for reference.
i tried nothing for now. just had a disaster with vscode accidently installed conda environment and had to remove it. and i am not sure if it is completely removed or not.
Related
I am relatively new to python and would like to install it the "right" way (of which, of course, there are many) to use both natively and with R through reticulate.
Here's what I have done so far:
I reinstalled MacOS Catalina from scratch and installed Miniconda with homebrew.
Through miniconda, I have updated to python 3.8.5.
Then, I installed reticulate in R (R version 4.0.2., RStudio version 1.3.1056). When reticulate asked me whether I wanted to install miniconda, I declined (since it was already installed.
I aliased python3 with python in my zsh terminal.
This is where the trouble started. I couldn't (and can't) get reticulate to recognize my python installation or, if I can get reticulate to recognize it, I can't get it to recognize my python environment.
As advised elsewhere, I changed my RETICULATE_PYTHON to /usr/local/bin/python3, which actually matches one of my python installations. Now I get the error Error: could not find a Python environment for /usr/local/bin/python3
I also tried setting my path to my miniconda python, which is located somewhere in /usr/local/Caskroom/miniconda/base/. Or more specifically, as obtained by type -a python python3, in /usr/local/Caskroom/miniconda/base/bin/python3. Unfortunately, once I changed the reticulate directory to the miniconda version, type no longer returns /usr/local/Caskroom/miniconda/base/bin/python3, for reasons that I don't understand.
When I now run type -a python python3, I receive the following output:
python is an alias for python3
python is /usr/bin/python
python3 is /usr/local/bin/python3
python3 is /usr/local/bin/python3
python3 is /usr/bin/python3
python3 is /usr/local/bin/python3
I don't know what happened to my miniconda installation (which still seems to work fine, when I run conda --version, I receive conda 4.8.3).
So to summarize the status quo:
Running python from the terminal works (both interactive and to execute a py file)
Reticulate recognizes the path I set in RETICULATE_PYTHON
My miniconda no longer appears when I run type -a python python3
Most importantly: reticulate does not recognize my environment even though I have created an environment with miniconda in the terminal and another environment in Rstudio using reticulate::conda_create() and I have also made sure to activate them.
So my question is, how can I get reticulate to
Recognize my miniconda python
Recognize the various environments that I create with conda (both inside and outside of R)
Last week I installed Anaconda but I continue to have problems using that environment in VS Code on Mac OS Mojave. For 2 weekends now I've struggled and struggled to try and figure out this path conflict myself but have not been able to get the interactive terminal in VS Code to match a terminal launched from the Anaconda Navigator. There seems to be ample materials online about how to run an Anaconda ENV in VS Code but after working through the possible solutions I can't figure out the root conflict and so it persists.
VS Code seems to indicate (bottom left status bar) that the correct 3.7.3 Conda environment is active in VS Code but $python --version returns 3.7.2 when tried. VS Code setting "python.pythonPath" for the workspace is pointing at the correct 3.7.3 python.exe location so I can only assume the conflict is with my PATH setting? Do I have to move the /Anaconda/bin to the front?
I really enjoy scripting with VS Code and would really like to get it up and working again with some of the tools from Anaconda.
Looks like you have both Mac python (from python.org) + anaconda, and the version from python.org is first in the PATH (the /Library/Frameworks/Python.framework stuff). You can move the python.org version later in the PATH, or even remove it altogether if you'd like.
If you decide to remove the other python, be sure you don't accidentally remove the MacOS system python (in /System/Library/Frameworks) or you will have to reinstall MacOS.
I have an issue where somewhere along the line i've installed python3 and it has overwritten the default python path which is for 2.7. So when I go to terminal and type in "python" it loads version 3.6.5 instead of 2.7. If i type in "python2.7 to explicitly run python i get an error saying its pointing to the 3.6 site-packages instead of 2.7.
derekchan#PandaMacPro:~/python$ python2.7
Your PYTHONPATH points to a site-packages dir for Python 3.x but you are
running Python 2.x!
PYTHONPATH is currently: "/usr/local/lib/python3.6/site-packages"
You should unset PYTHONPATH to fix this.
I've viewed other threads on this issue but it doesnt solve or help my problem. Is this a simple PYTHONPATH issue?
I just want to be able to type in "python" and it load version 2.7 instead of version 3 and not have issue with the conflicting python packages.
Consider using a distribution like Anaconda with built-in package management. With Anaconda you can easily isolate your Python2 and Python3 environments and not have to mess with PYTHONPATH
https://anaconda.org/
I installed both python 2.7.13 and python 3.6.2 with homebrew and updated my ~/.bash_profile as such:
# Homebrew
export PATH=/usr/local/bin:$PATH
Python3 was linked fine. However, "which python" would still give me
/usr/bin/python
while "which python2" produces
/usr/local/bin/python2
It looks like homebrew installed python 2 as "python2" and never linked "python" to the new installation. This is causing me a lot of trouble down the road when installing virtualenvwrapper etc.
By the way, I also did
brew link python.
Anybody know why this is and how to fix it?
Much appreciated!!
They change that behavior here
Today I’d like to announce Homebrew 1.3.0. The most significant change
since 1.2.0 is that brew install python no longer installs a python
binary without manual PATH additions and instead installs a python2
binary. This avoids overriding the system python binary by default
when installing Python as a dependency. It also paves the way to
eventually have python be Python 3.x.
You will have to symlink python to the version of python installed by homebrew that you want.
You can do:
$ln -s /usr/local/bin/python2 /usr/local/bin/python
To symlink python to the homebrew Python2.x installation or do:
$ln -s /usr/local/bin/python3 /usr/local/bin/python
to link it to the Python 3.x hombrew installation.
gsi-frank's solution solves the problem quite well but after using his solution, you might encounter problems with your pip3. Your pip3 might be linked to the old instance and therefore unusable for your new python instance.
Type which pip3 to see where your pip3's path.
If your path is linked to your new instance, then ignore the rest of this answer.
Type echo $PATH to see your current path. If it contains your old python instance's path then you will need to remove it from your .bash_profile
To solve this: check your .bash_profile and see if there is a path to your old python instance.
If the old path is in there, you can delete it.
I had this problem and here's a link to the question if needed:
How to change pip3 path after installing python with homebrew?
To find your .bash_profile:
Go to your Finder
Right click and click Go to a folder... and type ~
Press CMD + shift + . to see hidden files
Right click your .bash_profile and open in a text editor
So I downloaded a module, but when I tried to use it in a program, Python threw the error:
"ImportError: No module named markovify"
When I go to try to change my .bash_profile, it shows this:
"# Setting PATH for Python 3.5
The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH"
I've been using 2.7.10 all this time, and Terminal defaults to it. (When I type in Python, that's the version it says I'm using)
I'm trying to get pip to install modules for python 2.7.10 to a different folder.
What's weird is this: I seem to have installed pyparsing with pip and it seems to work. I tried installing markovify and it throws this error message.
What am I missing?
When I go to try to change my .bash_profile, it prints this
That suggests you're using some tool to change your profile. Did you also use that tool to install markovify? You need to be clear about your environment when you have environment questions! :-)
If you installed markovify from the command line, I'd suggest opening a new terminal and running these commands, just to make sure you're working from where you think you are:
$ python --version
Python 2.7.10
$ command -v python
/usr/bin/python
The most likely problem, it seems to me, is that you got a bit tangled up and wound up doing something other than what you intended. From a fresh start, provided you're starting with the environment you want, pip should, you know, Just Work.
I'm trying to get pip to install modules for python 2.7.10 to a different folder.
That's possible to do, but are you sure that's what you want? Usually if you're using the Python interpreter you intend to, and haven't putzed with PYTHON_PATH & friends, when you run pip, it will install to its default location, which sure enough is where Python will look for it when you say to import it.
As an experiment, you might check if markovify was somehow installed for Python 3.5. Try
$ /Library/Frameworks/Python.framework/Versions/3.5/bin/python -c 'import markovify'
(You might also want to check that the Python interpreter is in fact in that folder and has that name.)
When you're working on more than one Python version, you should work on Virtual Environments:
Virtual Env on Hitchhiker's Guide