First of all, there are too many stories about building a difficult environment in the world.
--Set for each folder --To be able to change for each project --You can save your settings --Create requirement.txt for later!
No, real beginners like us don't need it, so please tell me only the shortest route. It is a story. Personally, I think it's a waste to not be able to start by stumbling on something that is not needed in the current development. All you have to do is set the minimum settings and move as you see fit.
If you build an environment that is properly prepared, some people will get mounts in the future, and some people will point out the right thing, but if you are a beginner and want to get started, this is the way to go! I wrote that. You can get started with Python in as little as 10 minutes.
However, for those who have hit the command prompt and Bash commands a little. Someone who knows about cd, ls and pwd. If you don't want to type a command or a line, give up writing code and rely on a data robot.
Anaconda is very fast. Download and install Anaconda. It's heavy, but you can put it in. Just move. This article is easy to understand.
[Download and install Anaconda](https://qiita.com/t2y/items/2a3eb58103e85d8064b6#windows-%E3%81%A7%E3%81%AE%E3%82%A4%E3%83%B3%E3 % 82% B9% E3% 83% 88% E3% 83% BC% E3% 83% AB% E6% 96% B9% E6% B3% 95)
Once installed, it's easy to use without using the Anaconda GUI at all. As a result, I got used to it. Create a virtual environment at the command prompt (or Anaconda prompt). Why do you need a virtual environment? What? It's written all over the place, so let's google it.
For example, if you want to create a python3.7 system environment, just hit the following. Only env_name should be your favorite name. Personally, I recommend a name like py37_project so that you can see the version.
conda create -n env_name python=3.7
After that, activate the virtual environment and add the packages you need. The following is an example.
conda activate env_name
conda install numpy matplotlib
conda install scikit-leran
For those who want to know more, the following article is detailed.
[For beginners] Create a virtual environment with Anaconda
Now I have two choices, VS CODE or PyCharm. Personally, it's one of VSCODE, but I think PyCharm is easier to set up. What is launch.json so delicious for an amateur? I wonder if it's a level. I didn't really understand it in the past. .. I think PyCharm works when you click it for the time being.
Select project interpreter from the settings. [Python development environment memo](https://qiita.com/mm_sys/items/8fae23d569c42453c69b#project%E3%82%92%E4%BD%9C%E3%81%A3%E3%81%9F%E5% BE% 8C% E3% 81% AB% E5% A4% 89% E6% 9B% B4% E3% 81% 99% E3% 82% 8B).
If you include a Python extension, the Interpreter selection will be suggested, and you can change it by pressing the icon at the bottom left. [How to build Python and Jupyter execution environment with VS Code](https://qiita.com/SolKul/items/f078877acd23bb1ea5b5#python%E3%82%A4%E3%83%B3%E3%82%BF%E3% It is written in 83% 97% E3% 83% AA% E3% 82% BF% E3% 82% 92% E8% A8% AD% E5% AE% 9A% E3% 81% 99% E3% 82% 8B) ..
Hello, World
After that, for the time being, create a file called main.py and execute the following to move it.
main.py
print('Hello, World')
The Mac is extremely incompatible with Anaconda (rumors), so I put Pyenv and Virtualenv quietly. Pipenv may be good for a while! I thought, but in a blink of an eye it wasn't updated and disappeared somewhere (I'm aware) I also used Pipenv a long time ago, and the environment broke before I knew it, and I don't have good memories. I'm sorry for Pipenv followers.
As long as Homebrew is included, it is a single command. See below for more information.
Comfortable python environment with MacOS, Homebrew and pyenv.
brew install pyenv
Don't be afraid to add it to your Shell settings. Well, if you want to run Python on a Mac, you should be able to edit this much. Add these three lines to your .zshrc or .bash_profile.
shell:.zshrc,.bash_profile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
After completing the settings, restart the shell or execute the following.
zsh -l
or
source ~/.bash_profile
pyenv install --list
pyenv install 3.7.7
pyenv install 3.7.6
You can put as many types as you like. Enter the version you want to use.
brew install pyenv-virtualenv
Now you can create a virtual environment based on 3.7.7.
pyenv virtualenv 3.7.7 env_name
After that, you can add modules just like anaconda.
pyenv activate env_name
pip install numpy matplotlib
pip install scikit-leran
You can also link the environment to the folder and do such fashionable and convenient things, so please refer to here.
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
There are many in-house inquiries asking, "I really want to use Python for the first time." At the very least, I would like people who say that they can only hit commands to create and develop a virtual environment.
I think there are people who think that Anaconda should be installed from the beginning and Jupyter should be launched from the GUI, and that is also the correct answer.
However, in most cases, I think that .py will be created in the end, so I wonder if it's okay to prepare only that from the beginning. Personally, I think it makes sense to launch jupyter after preparing up to this point.
That's it.
Recommended Posts