1

I have a problem with installing modules in the virtual environment. When I install a module, for example, a module request, and then try to type pip list, there are several modules that I have never installed before appearing.

This was when I first made it :

Package    Version
---------- -------
pip        20.2.3
setuptools 41.2.0

and this is the first module I want to install which is requests:

Package    Version
---------- ---------
certifi    2020.6.20
chardet    3.0.4
idna       2.10
pip        20.2.3
requests   2.24.0
setuptools 41.2.0
urllib3    1.25.10

I want to create requirements.txt for my application but when I install every module I need, more modules that are not needed appear.

I saw tutorials about virtual environments and I did not find them experiencing this.

How do I solve the problem?

Axe319
  • 4,255
  • 3
  • 15
  • 31
  • You could remove all the lines corresponding to things you did not manually install. But do not remove pip or setuptools. – xrisk Oct 04 '20 at 16:16
  • but when I install pip-chill on venv and run it there is pip-chill too after running `pip-chill==1.0.0 pysimplegui==4.29.0 requests==2.24.0` Is it really like that? @xrisk – syafiqfadillah Oct 04 '20 at 23:29
  • Don’t install pip-chill in your virtual environment, install it outside. – xrisk Oct 05 '20 at 04:21
  • but when I install pip-chill outside of venv and run it it generates site-packages outside of venv ```black==20.8b1 ffmpeg==1.4 flake8==3.8.3 googletrans==3.0.0 instaloader==4.4.4 keyboard==0.13.5``` @xrisk – syafiqfadillah Oct 05 '20 at 07:18
  • Please ignore my earlier comment. Install pip-chill inside the virtualenv environment. You can just remove the `pip-chill` line manually from the output. – xrisk Oct 05 '20 at 08:11

3 Answers3

2
  • Make sure you refer to the right python or pip version first by using

python3 pip3

  • Try to uninstall the existing modules by pip uninstall

  • Try Anaconda

2

Those modules are dependencies on requests module. If you want to use this requests module you must have those dependencies. Otherwise you'll get an exception ModuleNotFoundError: No module named 'urllib3'.

Golamrabbi Azad
  • 369
  • 1
  • 9
1

When you install a package, pip will automatically install all dependencies of that package too.

In your case, requests depends on certifi, chardet, idna and urllib3, so those also get installed. You don't need to list those packages in your requirements.txt.

Take a look at pipdeptree if you want to visualize the dependencies of your pip packages.


Bonus: there exist dependency managers like poetry which keep track of your project's requirements for you. You might want to take a look at it if you don't want to manually maintain a requirements file in the future.

Safron
  • 802
  • 1
  • 11
  • 23