2
cat requirements.txt 
requests==2.22.0
pandas==0.24.2

I was getting a whole lot of errors. This was permission problem.
When I did sudo pip3 install -r requirements.txt there were no errors and Successfully installed pandas-0.24.2. I am on Ubuntu 20.04.1.
When on virtual environment, all packages get downloaded to /home/ubuntu/.virtualenvs/my-project/lib/python3.8/site-packages, then why the need for sudo ?

anjanesh
  • 593
  • 3
  • 10
  • 24
  • Installing Python packages in a Python virtual environment that is located anywhere in your home directory does not require the use of `sudo`. Did you activate the virtual environment before you tried to install Pandas in it? The command line prompt changes to a different prompt whenever the virtual environment is activated. – karel Jan 31 '21 at 13:18
  • Yes - I did `workon myproject` and everything is inside the virtual environment. This is new ubuntu setup so I thought that pandas require some global packages. – anjanesh Jan 31 '21 at 13:29
  • 1
    Pandas in a virtual environment does not require any global packages. Everything that is required is installed inside the virtual environment by pip including all dependencies. Also your package location shows that pandas has been installed globally by pip3 *outside* the virtual environment, the same as would be the case if you had not activated the virtual environment with `source bin/activate` first. – karel Jan 31 '21 at 13:31

1 Answers1

3

Pandas in a virtual environment does not require any global packages. Everything that is required is installed inside the virtual environment by pip including all dependencies. Also your /home/ubuntu/.virtualenvs/my-project/lib/python3.8/site-packages package location shows that pandas has been installed globally by pip3 outside the virtual environment, the same as would be the case if you had not activated the virtual environment with source bin/activate first.

Either you didn't activate your virtual environment before trying to install packages in it or your virtual environment is trashed. If activating the Python virtual environment doesn't help, then delete the virtual environment and create a new one from scratch. This time you will get the latest version of pip3 installed in the virtual environment by default, and you should be able to install Python packages in it with pip3 without using sudo.

karel
  • 110,292
  • 102
  • 269
  • 299
  • These are the errors : https://pastebin.ubuntu.com/p/2M5bGfdnxG/ - which shows pandas 1.0.5 when I try to do `pip3 list` in my virtual environment. But I need 0.24.2 – anjanesh Jan 31 '21 at 13:43
  • Don't use a requirements.txt file to install packages. Instead install the packages that are listed in the requirements.txt file manually with pip3 one a time. – karel Jan 31 '21 at 13:45
  • I tried did that too - same errors. – anjanesh Jan 31 '21 at 13:47
  • 1
    Don't waste any more time trying to install packages in this trashed virtual environment. Delete it and make a new one. – karel Jan 31 '21 at 13:51
  • Can I create a new one and test the same steps without deleting the current one ? This is for a django 2.2 project for which there are some 40 packages. – anjanesh Jan 31 '21 at 13:54
  • There's no need to delete the old Python virtual environment. Just give the new Python virtual environment a different name so you know which virtual environment is the new one and which one is the old one. – karel Jan 31 '21 at 13:56
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/119158/discussion-between-karel-and-anjanesh). – karel Jan 31 '21 at 13:58