2

I've been going around but was not able to find a definitive answer...
So here's my question..

I come from javascript background. I'm trying to pickup python now.
In javascript, the basic practice would be to npm install (or use yarn)
This would install some required module in a specific project.

Now, for python, I've figured out that pip install is the module manager.
I can't seem to figure out how to install this specific to a project (like how javascript does it)
Instead, it's all global.. I've found --user flag, but that's not really I'm looking for.

I've come to conclusion that this is just a complete different schema and I shouldn't try to approach as I have when using javascript.
However, I can't really find a good document why this method was favored.
It may be just my problem but I just can't not think about how I'm consistently bloating my pip global folder with modules that I'm only ever gonna use once for some single project.

Thanks.

Hyunwoo Lim
  • 312
  • 3
  • 15
  • 2
    Related: [What is a virtualenv, and why should I use one?](https://stackoverflow.com/q/41972261/4518341) – wjandrea Jan 25 '20 at 23:34

2 Answers2

0

A.) Anaconda (the simplest) Just download “Anaconda” that contains a lots of python modules pre installed just use them and it also has code editors. You can creat multiple module collections with the GUI.

B.) Venv = virtual environments (if you need something light and specific that contains specific packages for every project

macOS terminal commands:

  • Install venv pip install virtualenv

  • Setup Venve (INSIDE BASE Project folder) python3 -m venv thenameofyourvirtualenvironment

  • Start Venve source thenameofyourvirtualenvironment/bin/activate

  • Stop Venve deactivate

  • while it is activated you can install specific packages ex.: pip -q install bcrypt

C.) Use “Docker” it is great if you want to go in depth and have a solide experience, but it can get complicated.

sogu
  • 2,738
  • 5
  • 31
  • 90
0

Pip is a program used to manage Python distribution. You usually have one system distribution which is by default managed by Pip. When you do pip install scipy, you install package scipy to your system Python. Everytime you try to import scipy after it will work because your system Python has it.

Project specific distributions are acomplished by using virtual environments. python -m venv env or venv env creates a copy of system Python interpreter, pip, setuptools and a couple of other essential tools. In other words, virtual environment created this way is empty.

To use created virtual environement one should use source env/bin/activate. After that, everytime you invoke python command it will use activated Python interpreter. When you install packages using pip, it will install them in the virtual environment rather than to your system python. To use system Python again use deactivate.

Such usage is actually prefered for projects because some user applications could rely on system Python and some packages, and installing, updating etc. could be potentionally dangerous.

Further reading: venv documentation

papercut
  • 163
  • 6