Как сделать python 3 основным mac os

Сделать python3 как мой python по умолчанию на Mac

Я пытаюсь сделать здесь python3 как мой python по умолчанию. За исключением python 2.7, который автоматически устанавливается на mac, я установил python3 с homebrew. Это сайт, за которым я следую. http://docs.python-guide.org/en/latest/starting/install3/osx/#install3-osx

Наверное, я хорошо следил за каждой инструкцией, недавно получил xcode, инструменты командной строки и homebrew. Но здесь возникает моя путаница.

Сценарий объяснит, какие изменения он внесет и предложит вам до начала установки. После того, как вы установили Homebrew, вставьте каталог Homebrew в верхней части переменной среды PATH. Вы можете сделать это, добавив следующую строку внизу файла

export PATH =/usr/local/bin: /usr/local/sbin: $ PATH

Я был действительно смущен, что это было, но я пришел к выводу, что я должен просто добавить следующую строку внизу файла

/.profile. Поэтому я открыл файл

/.profile открытым.profile в терминале и добавил следующую строку внизу. И теперь это выглядит так.

А потом я запустил установку python и надеялся увидеть python3, когда я делаю python —version. Но это просто показывает мне python 2.7.10. Я хочу, чтобы мой python по умолчанию был python3, а не 2.7

И я нашел небольшую подсказку с сайта.

Если вы все еще видите 2.7, убедитесь, что в PATH/usr/local/bin/используется ссылка на /usr/bin/

Может быть, он должен что-то сделать с PATH? Может ли кто-нибудь объяснить на простом английском языке, что такое PATH, и как я могу сделать свой python по умолчанию python3, когда я запускаю python —version в терминале?

Источник

Как сделать Python 3.5 моей версией по умолчанию на MacOS?

Я только что установил Python 3.5.1 на своем Mac (работает с последней версией OSX). Моя система поставляется с установленным Python 2.7. Когда я набираю IDLE в приглашении терминала, моя система подтягивает оригинальный Python 2.7, а не только установленный Python 3.5. Как мне настроить мою систему по умолчанию на Python 3.5.1, когда я открываю окно IDLE из терминала?

Поскольку Python 2 и 3 могут радостно сосуществовать в одной и той же системе, вы можете легко переключаться между ними, указав в своих командах, когда вы хотите использовать Python 3.

Итак, для Idle вам нужно набрать idle3 в терминале, чтобы использовать его с Python 3 и idle для его использования с Python 2.

Аналогично, если вам нужно запустить script или получить приглашение python от терминала, вы должны набрать python3 , если хотите использовать Python 3 и python , если вы хотите использовать Python 2.

Хорошо, чтобы ваша среда MacOS Python была настроена правильно с самого начала, убедившись, что установки Homebrew имеют приоритет перед двоичными файлами MacOS. Вы хотите его в usr/local/bin не в MacOS по умолчанию usr/bin .

Может также создавать псевдонимы для обоих.

Источник файла, чтобы убедиться, что он вступает в силу для текущего сеанса

Установка и настройка Homebrew и т.д.

Когда все будет завершено python3 , pip3 , virtualenv и virtualenvwrapper.sh все будут в usr/local/bin .

Результат

Каждый раз, когда я устанавливаю что-либо или использую команды типа mkvirtualenv , по умолчанию используется Python 3.

Вы можете использовать команду python3 (вместо использования python ) или просто удалить версию 2.7, если вы ее не используете.

Если у вас нет каких-либо скриптов python 2, вы можете удалить python2. Но это не проблема, когда они оба установлены. Вам просто нужно использовать другой путь python3 для запуска IDLE.

Я бы предпочел, чтобы они оба были установлены так, если у вас есть какие-либо скрипты, которые находятся в python 2, вы все равно можете их запускать или вам нужно перенести их в python3.

Читайте также:  Как установить mustek 1200 ub plus для windows 10

Вы можете переключиться на любую версию python в своем проекте, создав виртуальную среду.

  • virtualenv -p/usr/bin/python2.x(или python 3.x)

Если вы просто хотите запустить программу в определенной версии, просто откройте оболочку и введите python2.x или python3.x

Набрав python , вы на самом деле ссылаетесь на ссылку.
Вы найдете его местоположение с $ which python . В моем случае это было /usr/local/bin/python . пойдите туда $open /usr/local/bin/ и просто удалите исходный python, python-config и простаивайте, поскольку они
идентичный 2.7 файлам в той же папке.
Затем дублируйте файлы 3.5 и переименуйте их в то, что вы только что удалили.

Это также изменяет ссылку по умолчанию для других редакторов, таких как Sublime_ReplPython, и поэтому обновляет ее до версии 3.5. Это была моя главная проблема со стандартной установкой.

Перейти к типу терминала:

Это должно установить Python по умолчанию как python3.x

Делай правильно, делай правильно!

Откройте свой терминал,

входной python -V , скорее всего, показывает: Python 2.7.10

вход python3 -V , скорее всего, показывает: Python 3.7.2

ввод, where python или which python , скорее всего, показывает: /usr/bin/python

ввод, where python3 или which python3 , скорее всего, показывает: /usr/local/bin/python3

добавьте следующую строку внизу файла переменной среды PATH в файле

/.bash_profile в Bash или в

alias python=’/usr/local/bin/python3′ ИЛИ alias python=python3

/.bash_profile под Bash или исходный файл

Выйдите из терминала.

Откройте свой терминал и python -V , вероятно, он показывает: Python 3.7.2

Источник

Make Python 3 default on Mac OS? [duplicate]

I would like to ask if it is possible to make Python 3 a default interpreter on Mac OS 10 when typing python right away from the terminal? If so, can somebody help how to do it? I’m avoiding switching between the environments.

2 Answers 2

Method 1:

/.bash_profile , set an alias for your python3

Method 2(I use this way to keep multiple python versions):

Install python3(the virtualenv python3 on my machine is env-3.5) by virtualenv , in

/.bash_profile activate certain virtual environment:

I suggest use a virtual environment, it will affect your system even packages messed up.

update:

Did research on anaconda which data_garden commented. Here I post how I installed it:

  • Go to page https://www.anaconda.com/download/#macos find the package meet your system requirement, for me it’s MacOS
  • Add to system PATH export PATH=$HOME/anaconda3/bin:$PATH into .bash_profile
  • Search available python versions conda search «^python$»
  • Create env: conda create -n env-3.6.5 python=3.6.5 , env-3.6.5 is the name of the new created env
  • Activate env: source activate env-3.6.5 , add it into .bash_profile

You can run conda env list to display all virtual environments you have created.

Источник

Make python3 as my default python on Mac

What I’m trying to do here is to make python3 as my default python. Except the python 2.7 which automatically installed on mac, I installed python3 with homebrew. This is the website that I’m following. http://docs.python-guide.org/en/latest/starting/install3/osx/#install3-osx

I guess I followed every instruction well, got xcode freshly installed, Command line tools, and homebrew. But here’s my little confusion occurs.

The script will explain what changes it will make and prompt you before the installation begins. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

I was really confused what this was, but I concluded that I should just add this following line at the bottom of

/.profile file. So I opened the

/.profile file by open .profile in the terminal, and added following line at the bottom. And now it looks like this.

And then I did brew install python, and was hoping to see python3 when I do python —version. But it just shows me python 2.7.10. I want my default python to be python3 not 2.7

Читайте также:  Центр поддержки windows процесс

And I found a little clue from the website.

Do I have a Python 3 installed?

If you still see 2.7 ensure in PATH /usr/local/bin/ takes pecedence over /usr/bin/

Maybe it has to do something with PATH? Could someone explain in simple English what PATH exactly is and how I could make my default python to be python3 when I run python —version in the terminal?

Источник

How to set Python’s default version to 3.x on OS X? [duplicate]

I’m running Mountain Lion and the basic default Python version is 2.7. I downloaded Python 3.3 and want to set it as default.

How do I set it so that every time I run $ python it opens 3.3?

22 Answers 22

Changing the default python executable’s version system-wide could break some applications that depend on python2.

However, you can alias the commands in most shells, Since the default shells in macOS (bash in 10.14 and below; zsh in 10.15) share a similar syntax. You could put alias python=’python3′ in your

/.profile , and then source

/.profile in your

/.bash_profile and/or your

/.zsh_profile with a line like:

This way, your alias will work across shells.

With this, python command now invokes python3 . If you want to invoke the «original» python (that refers to python2) on occasion, you can use command python , which will leaving the alias untouched, and works in all shells.

If you launch interpreters more often (I do), you can always create more aliases to add as well, i.e.:

Tip: For scripts, instead of using a shebang like:

This way, the system will use python3 for running python executables.

/.bash_profile instead of

/.bash_profile after edit

You can solve it by symbolic link.

Then put the alias as follows:

Now save the file and then run the

Congratulation . Now, you can use python3 by typing python.

/.bash_profile, alias pip=’pip3′, source

/.bash_profile, pip —version

/.bash_profile everytime I re-opened my terminal? It reverts to python2 once I close and open the terminal again.

I encountered this issue as well, so I thought I should post an updated answer. Please note that this will only apply to a Mac-based setup (I haven’t tried it with Windows or any flavor of Linux). The simplest way to get this working is to install Python via Brew. If you don’t have brew installed, you will need to do that first. Once installed, do the following in at the terminal:

This will install Python 3. After it’s installed, run this:

You will see all of the links created by brew to its Python install. It will look something like this:

The first row in this example shows the python3 symlink. To set it as the default python symlink run the following:

You will have to reload your current terminal shell to use the new symlink in that shell. Run this command to reload your shell:

You’re all set now. Now, you can do:

and it should show:

All newly opened shell sessions will (should) automatically use the new symlink. To test this, open a new terminal shell and run the following:

Go to terminal type:

This will setup default python as python3.x

This worked for me. I added alias and restarted my terminal:

The following worked for me

Go to ‘Applications’, enter ‘Python’ folder, there should be a bash script called ‘Update Shell Profile.command’ or similar. Run that script and it should do it.

Update: It looks like you should not update it: how to change default python version?

I believe most of people landed here are using ZSH thorugh iterm or whatever, and that brings you to this answer.

You have to add/modify your commands in

Читайте также:  Windows network sharing password

Suggestions to alias python to python3 will cause problems with virtual environments that set the version of python (eg: pyenv). With pyenv, you can set the version globally like so:

and then in any specific project, you can create a .python-version file which has the python version inside of it:

This is the best way to manage multiple versions of python on a system in my opinion.

In this article author discuss three ways of setting default python:

  1. What NOT to do.
  2. What we COULD do (but also shouldn’t).
  3. What we SHOULD do!

All these ways are working. You decide which is better.

I think when you install python it puts export path statements into your

/.bash_profile file. So if you do not intend to use Python 2 anymore you can just remove that statement from there. Alias as stated above is also a great way to do it.

Here is how to remove the reference from

/.bash_profile — vim ./.bash_profile — remove the reference (AKA something like: export PATH=»/Users/bla/anaconda:$PATH») — save and exit — source ./.bash_profile to save the changes

Mac users just need to run the following code on terminal

3.x.x should be the new python version.

This will update all the system links.

On MacOS

Step-1: Upgrade python to latest version by: $ brew upgrade python

Step-2: Go to home: $ cd

Step-3: open .bash_profile

Setting PATH for Python 3.8

PATH=»/Library/Frameworks/Python.framework/Versions/3.8/bin:$» export PATH

Step-4: Save the file. And compile it by:

Step-5: Check the python version:

Step-6: Thats all.

I’m not sure if this is available on OS X, but on linux I would make use of the module command. See here.

Set up the modulefile correctly, then add something like this to your rc file (e.g.

This will make it so that your paths get switched around as required when you log in without impacting any system defaults.

For me the solution was using PyCharm and setting the default python version to the the one that i need to work with.

install PyCharm and go to file ==> preferences for new project, then choose the interpreter you want for your projects, in this case python 3.3

If you use macports, you do not need to play with aliases or environment variables, just use the method macports already offers, explained by this Q&A:

If you are using a virtualenvwrapper , you can just locate it using which virtualenvwrapper.sh , then open it using vim or any other editor then change the following

Change the line VIRTUALENVWRAPPER_PYTHON=»$(command \which python)» to VIRTUALENVWRAPPER_PYTHON=»$(command \which python3)» .

If you are using macports, that has a easier way to do:

port install python37

after install, set default:

sudo port select —set python python37

sudo port select —set python3 python37

restart your cmd window, finished.

Well. It’s kinda old. But still deserves a good answer.

And the good one is You Don’t Wanna Touch The Default Python On Mac.

Install any Python version you need via Homebrew or whatever and use it in virtualenv. Virtualenv is often considered to be something crap-like, but it’s still way, wayyyy better than changing python version system-wide (macOS is likely to protect itself from such actions) or user-wide, bash-wide. whatever. Just forget about the default Python. Using playgrounds like venv is what your OS will be most, very most grateful for.

The case is, for example, many modern Linux distributions get rid of Python2 installed out-of-the-box, leaving only Python3 in the system. But everytime you try to install something old with python2 as a dependency. hope you understand what I mean. A good developer doesn’t care. Good developers create clean playgrounds with python version they desire.

Источник

Оцените статью