You can install the package and analyze it, but it will be more convenient if you can create a virtual environment. As a merit of creating a virtual environment
--Even if the environment is buggy, you only have to delete the virtual environment ――Easy to share the environment when working with someone in the same environment --Packages that you don't normally use can only be installed in a virtual environment
I wonder if it is big.
By the way, when you install a normal package, you can install it by executing pip install package name
in the terminal (powershell).
Therefore, if you don't need a virtual environment, you can manage packages around pip
.
(People who create venv described later in a virtual environment will do it with pip)
It's basically good to make venv (short for ** v ** irtual ** env ** ironment?), But using pipenv
made it easier, so I'll introduce that.
In the case of venv (I wonder if this expression is correct), powershll goes to the project directory (use the cd
command) and then, depending on the version, I only know Python3 So
python3 -m venv virtual environment name
Then you can create a virtual environment. All you have to do is manage the package with pip
.
At first I used to do this all the time, but it's getting more and more troublesome. .. ..
So, if you try the method using pipenv
as another environment construction method, it's quite easy. Well, I think venv is okay at all, so I think it's okay if you like it.
"Venv: Python virtual environment management" explains this method.
After starting VS Code, go to the terminal, start "new terminal",
pip install pipenv
Just execute. Create a new folder and in a new terminal
pipenv --python 3.8
The part of "3.8" that is executed like this is my Python version, so change it according to your own version. When you run it, Explorer on the left? I wonder if I can do something like ".venv".
Then create and open a new file " filename.py
".
You can choose the Python to use from " Ctrl + Shift + P
"or" Select Python ... "in the lower left to select the Python to use, so you can select the one you just made (maybe parentheses) That's the one with the writing.) The path is also written, so select the one with ".venv /" written somewhere.
If you write something and execute it (F5
and ʻEnter`), it will be executed.
It is attractive that you can also install packages with pipenv
.
Install in the terminal
pipenv install package name
When uninstalling with, just do "uninstall" above.
If you want to try it out, use numpy
(called NumPy, which stands for Numerical Python) that anyone can use (package names are all lowercase).
NumPy is a Python package that specializes in numerical calculations, but it may be convenient to put it in because it does quite a lot from the basics.
It's easy, isn't it? So, let's talk a little about sharing. Basically, use pip freeze
to create requirements.txt
and move it to another PC.
pip install –r requirements.txt
However, if you manage the package with pipenv
, it will be appreciated that such files will be updated automatically. That information is stored in the Pipfile
. In the case of Pipfile, move to another PC and
pipenv install --dev
You can do like this.
Also, if you used to manage packages with requirements.txt
,
pipenv install -r ./requirements.txt
If so, the environment can be reproduced on a new PC. It's a really convenient time compared to the past.
Recommended Posts