Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python env does not allow to use pip before and after activated #874

Open
macOneOone opened this issue Dec 27, 2024 · 3 comments
Open

Python env does not allow to use pip before and after activated #874

macOneOone opened this issue Dec 27, 2024 · 3 comments

Comments

@macOneOone
Copy link

@N-Holzschuch,

Found an issue on python -m venv where I can’t use pip to install anything.

Because of that, can’t :

  • Install package using pip.
image
  • Deactivate the virtual environment.
  • Install pip because python3.11 from a-shell does not support ssl.
image

The reason why is that happened is because virtual environments are created by default without pip.

Did some researches on pyvenv.cnf file and found that python-venv module runs this runs python3 -m venv --copies --without-pip by default.

According to help file, since we can’t install a new pip because it cames by default, I guess we should be shared this module, unless I misunderstood the real reason behind virtual environments.

image
@holzschu
Copy link
Owner

In my experience, pip works fine with virtual environments as long as you don’t run it inside the directory of the virtual environment.

@macOneOone
Copy link
Author

Okey, so what’s the point of having virtual environments if I can’t pip in it?

I had to copy the usage of virtual environment to explain why it shouldn’t be happening.

Please, feel free to read the information from doc.python.org

The venv module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site directories. A virtual environment is created on top of an existing Python installation, known as the virtual environment’s “base” Python, and may optionally be isolated from the packages in the base environment, so only those explicitly installed in the virtual environment are available.

When used from within a virtual environment, common installation tools such as -pip will install Python packages into a virtual environment without needing to be told to do so explicitly.

A virtual environment is (amongst other things):

Used to contain a specific Python interpreter and software libraries and binaries which are needed to support a project (library or application). These are by default isolated from software in other virtual environments and Python interpreters and libraries installed in the operating system.
Contained in a directory, conventionally named .venv or venv in the project directory, or under a container directory for lots of virtual environments, such as ~/.virtualenvs.
Not checked into source control systems such as Git.
Considered as disposable – it should be simple to delete and recreate it from scratch. You don’t place any project code in the environment.
Not considered as movable or copyable – you just recreate the same environment in the target location.

@holzschu
Copy link
Owner

To clarify: once you have activated the virtual environment, running pip will install packages in the virtual environment. So you can add more packages, and so on. pip will install packages in the active virtual environment (background_process in your case).

The issue (which I'm trying to fix, but it's difficult) is just that the current working directory while running pip has to be outside of the directory of the virtual environment.

To recap:

~/Documents > source background_process/bin/activate
(background_process) ~/Documents > pip install lots-of-packages
(...)
(background_process) ~/Documents > pip list --user
(background_process) ~/Documents > 

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants