Python Forum

Full Version: Python use of virtual environments
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need the ability to use python virtual environments, currently I can create them using python -m venv venv but when I try to import libraries into the virtual environment I get an access denied error. I am using my company laptop with no admin rights, running Win 11
Hi bre67e49
I hope you are doing well
I am new to this forum. Did you try to open the command prompt as Administrator and then try again?
Hi

I'm new to this forum too :) I haven't got admin rights on my work laptop - assume this is the issue
Are you activating your virtual environment before you try to install packages? If not, you are trying to install the packages into your system python.

If you are using the cmd shell in windows, run the "activate.bat" file in your virtual environment\Scripts folder.
If you are using the powershell in windows, run the "Activate.ps1" file in your virtual environment\Scripts folder.
If you are using Linux or MacOS run the "activate" file in your virtual environment/bin/activate folder.

In all examples above "virtual environment" refers to the path to your virtual environment.

You can configure most IDE's to automatically activate your virtual environment. How this is done depends on what IDE you are using. In Linux you can configure automatic activation of your virtual environment when you enter a specific folder.

To learn more about activating virtual environments:

https://python.land/virtual-environments/virtualenv
Since you have no admin rights, try these steps:

1. **Create the virtual environment in your user folder:**
`bash
cd %USERPROFILE%
python -m venv my_venv
my_venv\Scripts\activate
`

2. **Use the --user flag when installing packages:**
`bash
pip install --user package_name
`

3. **Change the pip cache directory if needed:**
`bash
pip install --cache-dir=%USERPROFILE%\pip_cache package_name
`