Cannot install python 3 in visual studio code on my mac - python

I have been trying for several hours now but still I cannot download python 3.
I already have python extension installed and in the bottom right corner of my screen it even says python 3.10.0.
But when I go in the terminal and type "python" this is what it shows me:
Python 2.7.16 (default, Jan 26 2020, 23:50:38)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
And I cannot install Vpython because the terminal thinks I am still using
python 2!!!
Please help.

It's possible you are calling the wrong version of python from your terminal. Try calling python3 explicitly, see if that works? Some useful command line calls:
which python \ which python3 -> will show you the path to executable python program
python --version \ python3 --version -> will show you the version of python
pip --version -> will show you the version of pip
If not found, install pip
As an additional step, it's possible that the newer version of python hasn't been added to your profile.
Here is a solution for that: Permanently add a directory to PYTHONPATH?

Related

Python official newest version, Homebrew version and installed version differ on macOS

According to python.org, 3.8.2 is currently the latest version of
Python.
When I try to upgrade python3 using Homebrew (freshly
upgraded), it tells me version 3.7.6_1 is already installed.
When I ask python3 for it's current version, it tells me 3.7.3.
See terminal runs:
Nannas-Computer:some_folder username$ brew update
Already up-to-date.
Nannas-Computer:some_folder username$ brew upgrade
Nannas-Computer:some_folder username$ brew upgrade python3
Warning: python3 3.7.6_1 already installed
Nannas-Computer:some_folder username$ python3 --version
Python 3.7.3
Why are all these versions different, and how can I install the 3.8.2 version on my mac (macOS Mojave, version 10.14.6)?
You can install Python 3.8.x using command:
brew install python#3.8
As it's not main Python distribution on Homebrew, by default it's not accessible by simple typing python3. Binary is located in /usr/local/Cellar/python#3.8/3.8.2/bin/python3.8 and you can create a symlink to it or use directly by typing full path.
It's not that cumbersome as one may think because usually the only thing you need to do is to create a virtual environment and activate it. Since then it'll be your default Python (for this virtualenv):
$ /usr/local/Cellar/python#3.8/3.8.1/bin/python3.8 -m venv my_venv
$ source my_venv/bin/activate
(my_venv)$ python
Python 3.8.1 (default, Dec 27 2019, 18:06:00)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
After some research I found out the following reasons:
It is possible to upgrade to Python 3.8.2 via Homebrew, but it isn't listed as supplying python due to some complications. See status here. Until this issue is done, 3.7.6_1 is the newest version you can upgrade to (as Homebrew kept telling me).
When I ran python3 --version in terminal, it returned Python 3.7.3 because I had installed this version myself at some point from the official website, without using Homebrew. Upgrading python to 3.7.6 via Homebrew had no effect on this dominating installation of python. I got rid of the manually installed version using this useful answer, after which I reinstalled python properly using Homebrew just to be on the safe side and now I finally have:
Nannas-Computer:some_folder username $ python3 --version
Python 3.7.6

Python not finding modules

Even after installing selenium using pip on Python 3.6.3, whenever I try to run a code with import selenium I get the message that ModuleNotFoundError: No module named 'selenium'.
I usually use Anaconda Prompt and run my codes in Jupyter notebook, but I made the installation also in regular cmd.
Does anyone have an idea about how to solve this?
From your command prompt you can run:
$ conda list
This will list all of the packages in your environment.
Ensure that your system is running the anaconda flavor of python.
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
To ensure the uniformity of package management you could use:
$ conda install -c conda-forge selenium
Edit: As you can see the path at which the "Requirement is already satisfied" is not the path in which Anaconda is installed.
You may or may not get a message saying that selenium is already installed. In that case, you may just need to ensure that you are in the conda environmnet—either a virtual conda environment or running right off the anaconda installation.
If you use the Anaconda GUI and you can install packages through this, I would try to do so. The point of virtual environments is to void these issues. I would bet importing selenium at the command prompt works, however, trying to use it within a Jupyter Notebook fails—because it is outside the environment, virtual or otherwise.
Updated:
Installation and testing of installation:
windows
macos
linux - the linux people know what's up.
I think you have both python 2.x and python 3.x installed on your system.
When you do pip install selenium, the module gets installed for python 2.x.
To install the module for python 3.x, use pip3 install selenium.

Two versions of python on mac

I have what I'm pretty sure is a simple problem- just wondering how I can/should resolve it. As a disclaimer, I'm not very experienced when it comes to working with the terminal, understanding what files are installed and where, etc.
As the title says, I'm working on a Mac.
I've been trying to get pandas and other related packages working on Python- my issue is that when I type:
python --version
In the terminal, I get Python 2.7.10, whereas when I type
sys.version
In Idle, I get 3.3.0. (More exactly, the message is: '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]')
From some research, I'm pretty sure the 2.7 is python which came with my Mac, and 3.3 was installed by me. I used the command
pip install pandas --user
In the terminal, which seemed to work- though, of course, when I type "import pandas" or "import numpy" in IDLE, it can't find the package. So my question is: How to either:
1) Change IDLE so it "points to" (?) version 2.7.
2) Download the latest version of Python (3.3 is outdated it seems) and then download packages for it. (And uninstall 3.3? Will that happen automatically?)
As I'm only a beginner, I don't have any real reason to prefer 2.7 or 3.x, so suitable advice on this point is appreciated as well. The more explicit instructions the better. Thanks!

OS X - Deciding between anaconda and homebrew Python environments

I use Python extensively on my Mac OS X, for both numerical applications and web development (roughly equally). I checked the number of Python installations I had on my laptop recently, and was shocked to find four:
Came with Mac OS X:
/usr/bin/python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Installed via Homebrew
/usr/local/bin/python
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Installed via Anaconda/Miniconda
~/anaconda/bin/python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, Oct 19 2015, 18:31:17)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
Came with the downloaded .pkg from python.org
/System/Library/Frameworks/Python.framework/Versions/Current/bin/python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
I decided to unify all of this, and use conda. I removed the Homebrew version and the Python.org download (kept the main system one). Conda is great for numerical computing, because I can install Jupyter/Numpy/Pandas in the root environment, and not have to bother install virtualenvs for every project.
But now my entire web development workflow is messed up. None of my virtualenvs work, since apparently one's not supposed to use conda and virtualenv together. I tried to create conda environments from the requirements.txt file. One package I was using with django was "markdown_deux", which is not available in the Conda repo. I looked at ways of building it, but creating a recipe takes a lot of effort (create YAML file, etc..)
Has anyone found a good compromise for this? I'm thinking of going back to the homebrew version for general use, and writing an alias for changing the path back to the conda version as necessary. Though this will also require tracking which one I'm using now..
I use Homebrew Python for all my projects (data science, some web dev).
Conda is nothing fancy, you can have the same packages by hand with a combination of pip and Homebrew science. Actually, it is even better because you have more control on what you install.
You can use your virtualenvs only when you do web development. For the numerical applications you will probably want to have the latest versions of your packages at all times.
If you want to update all your packages at once with pip, you can use this command:
sudo -H pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo -H pip install -U
EDIT: This answer is old, if you want a more up-to-date comparison, I found this nice blog article which compares the two approaches:
https://towardsdatascience.com/pipenv-vs-conda-for-data-scientists-b9a372faf9d9
I still use Homebrew Python, and pip / pipenv over conda.
Workflow that I've found the best:
Use conda for virtual environment management. Never use / install into system python.
Use pip to install into the active virtual environment, just like normal.
Use conda packages only for hard to install software, such as Qt.
Automation / extras
Use autoenv or direnv and automatically activate virtual environments when you enter a directory by putting the conda command inside the .env or .envsrc file.

What is the difference between running "python" and "python2.7" on a Mac OS X?

When I run python from a terminal on my Mac, I get the following first two lines back:
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
When I run python2.7, I get this:
Python 2.7.5 (default, May 19 2013, 13:26:46)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
I can recognize scipy and numpy in python2.7, but not in plain python.
What precisely is the difference between these? Is there any way I can make python import scipy? Can I just alias python2.7 to python and forget about this?
Those are two different pythons.
Try whereis python and whereis python2.7 to get their specific locations.
On a Mac (at lesat with OS X 10.7.0 through the latest 10.8.x), the pre-installed Python at /usr/bin/python and /usr/bin/python2.7 is Apple's 2.7.2 build.
If you have two different 2.7.5 builds, you must have installed them manually. And nobody but you can possibly know how you did that.
The which command may help. For example, you may find that the first python on your PATH is a /usr/local/bin/python which is a symlink to /usr/local/Cellar/python/2.7.5/bin/python, while the first python2.7 on your PATH is /opt/local/bin/python2.7, which is an executable. That would mean that you installed a Homebrew Python 2.7.5, and you also installed a MacPorts Python 2.7.5, and you did the latter in such a way that it didn't create a python symlink, and you've got MacPorts higher on your PATH than Homebrew.
But whatever you've done, it scarcely matters. If you don't understand how to manage this stuff yourself, the best thing to do is to uninstall all of the extra Pythons you installed and just use a single Python 2.7. That means you will need to reinstall any modules, of course, but it's worth doing.
I know some people believe that it's worth getting one additional Python 2.7 installation and using that in place of Apple's, but nobody is going to tell you to get two additional Python 2.7 installations and use both of them.
man python on the mac will tell you "To support multiple versions, the programs named python and pythonw now just select the real version of Python to run, depending on various settings."
When you call 'python2.7' you are selecting the version, while the 'python' chooses a version based on what is available and environment variables like VERSIONER_PYTHON_VERSION=2.7

Categories

Resources