rbanffy / pip-chill

A more relaxed `pip freeze`
Other
555 stars 25 forks source link

`pip-chill` in a virtual environment seems to output the results of the global environment #53

Closed cycychenyi closed 2 years ago

cycychenyi commented 2 years ago

Environment

Description

I run pip-chill in a Python virtual environment, but it seems to output the results of the Python global environment.

What I Did

# activate a Python environment
.\venv\Scripts\activate

# install some Python packages
pip install python-docx
pip install docx2python

# run pip-chill in a Python virtual environment
pip-chill
# output:
# pip-autoremove==0.9.1
# pip-chill==1.0.1

# run pip list in a Python virtual environment
pip list
# output:
# Package        Version
# -------------- -------
# docx2python    1.27.1
# lxml           4.6.3
# pip            21.3.1
# pip-autoremove 0.9.1
# pip-chill      1.0.1
# python-docx    0.8.11
# setuptools     57.0.0

# deactivate the Python environment
deactivate

# run pip-chill in the Python global environment
pip-chill
# output:
# pip-autoremove==0.9.1
# pip-chill==1.0.1

# run pip list in the Python global environment
# Package        Version
# -------------- -------
# pip            21.3.1
# pip-autoremove 0.9.1
# pip-chill      1.0.1
# setuptools     57.4.0
fgierlinger commented 2 years ago

I can confirm this behaviour. As a workaround you could install pip-chill inside the virtualenv. In case you have pip-chill installed globally and inside the virtualenv, you need to exit and reenter the virtual environment in order to use the local pip-chill

$ pip install pip-chill
$ mkvirtualenv pipchillvenv
(pipchillvenv) $ pip install ansible-core pip-chill
(pipchillvenv) $ pip-chill
ansible-core==2.11.4
ansible-lint==5.2.1
commitizen==2.17.9
molecule-docker==1.1.0
pip-autoremove==0.9.1
pip-chill==1.0.1
pre-commit==2.13.0
virtualenvwrapper==4.8.4
yamllint==1.26.3

# as noted, running pip-chill directly will use the global
# instead of the local pip-chill
(pipchillvenv) $ deactivate
$ workon pipchillvenv
(pipchillvenv) $ pip-chill
ansible-core==2.12.0
pip-chill==1.0.1
cycychenyi commented 2 years ago

@fgierlinger Thank you for response! A few days ago I reinstall Windows for some reasons, pip-chill can work perfectly in virtual environments now.

Ed1123 commented 2 years ago

Is there a way to make pip-chill global and don't include global packages? Installing it in the venv have the small drawback of having pip-chill in the requirements.txt file.