I know many similar questions are there, but I am having this issue in a virtual environment.
I am trying to install Pandas on my machine, and I already have a virtual environment in which I am trying to install Pandas with pip. A couple of days ago, I installed TensorFlow. That worked fine, but it now gives me an error:
Here's what is happening:
cd /var/forjupyter/jupyter
source env1/bin/activate
pip3 install pandas
Output:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pandas
Using cached pandas-2.2.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (15.6 MB)
Requirement already satisfied: numpy>=1.23.2 in ./env1/lib/python3.11/site-packages (from pandas) (1.26.4)
Requirement already satisfied: python-dateutil>=2.8.2 in ./env1/lib/python3.11/site-packages (from pandas) (2.9.0.post0)
Collecting pytz>=2020.1
Using cached https://www.piwheels.org/simple/pytz/pytz-2024.1-py3-none-any.whl (505 kB)
Collecting tzdata>=2022.7
Using cached https://www.piwheels.org/simple/tzdata/tzdata-2024.1-py2.py3-none-any.whl (345 kB)
Requirement already satisfied: six>=1.5 in ./env1/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)
Installing collected packages: pytz, tzdata, pandas
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/var/forjupyter/jupyter/env1/lib/python3.11/site-packages/pytz'
Check the permissions.
When I try sudo gives me an error:
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
For more information visit http://rptl.io/venv
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
Note: you may need to restart the kernel to use updated packages.
With apt install python3-pandas
, successful installation was done, but when I tried to access it in a notebook on env1, Pandas is not found. When I try notebook on the main environment, TensorFlow is not found. What can I do? Can I import Pandas to env1
?
I have the same error as first in Jupyter Notebook with %pip or pip for installation of any package.
The question (issue) started as mentioned above in the question, but I have realized that if you create a virtual environment outside the home directory, especially somewhere in a place where root access might be needed, you are going to get the above error.
If you have env outside home and try to use pip, you will get permission denied, because you are not root, but if you use sudo, it is assuming you are installing the package system wide. So if you want to install something without any risk, like break-system-packages
, create a virtual environment where the user can access it without any special permissions.