1

I am not able to activate the venv available in my project directory.

When I do the following it still doesn't activate the venv and I am not able to use python or pip installed in my venv.

/my_project$ source venv/bin/activate

(venv) /my_project$

It does show that the venv is activated but when I check python and pip, version and location it shows that both are from the root dir usr/bin/python & usr/bin/pip.

Venv Installation Process

/my_project$ python3.10 -m venv venv

It's working well in my new directory and I am also able to activate the venv but my existing venv in the project folder that I created yesterday is not starting. I am new to Linux and don't know much about it but I believe it has something to do with the Linux reboot as after the reboot this started happening. Any help would be appreciated. Thanks

OS: Ubuntu 20.04.4 LTS
system python: 3.8.10
python3.10: 3.10.5

  • 1
    Did you run any updates after creating the virtual environment? – Jacques Gaudin Jul 01 '22 at 16:26
  • What updates you are talking about? system updates or updating venv? – Jawad Mehmood Jul 01 '22 at 16:35
  • 1
    "when I check python and pip" What exactly do you do to check? – n. m. could be an AI Jul 01 '22 at 16:41
  • I check `whereis python` & 'whereis pip` & `pip list` which even shows packages that are not on my venv. Also `pip --version` which also show the pip directory too along with version. – Jawad Mehmood Jul 01 '22 at 16:44
  • @JawadMehmood System updates but it doesn't seem to be the problem. When checking use `which python`. See https://superuser.com/a/40304/598673 – Jacques Gaudin Jul 01 '22 at 16:54
  • 2
    Don't use `whereis` for this check. Use `which` instead. – n. m. could be an AI Jul 01 '22 at 17:50
  • 1
    How did you install `python3.10: 3.10.5`? There's a pretty good chance that the installation process set-up some environment variables that then disappeared with the reboot (you forgot to e.g. add them to your `~/.bash_login` or `~/.profile` )... – tink Jul 01 '22 at 18:17
  • @tink Thanks, man. My python3.10 was not added to the `PATH` variable. I have added it to the `~/.bashrc` file as I already have some other custom variable present there. But the thing about the `virtual environment` is that I have deleted the previous `venv` and installed a new one using `virtualenv`. I think the root of this problem is environmental path and after setting env path I hope this would not happen in the future – Jawad Mehmood Jul 02 '22 at 10:24

1 Answers1

0

perhaps try explicitly setting the python version when creating your venv:

i.e.

/my_project$ python -m venv venv python=python3.10

https://stackoverflow.com/a/61775880/14327910

and from (https://python.land/virtual-environments/virtualenv):

Blockquote Python 3.4 and above If you are running Python 3.4+, you can use the venv module baked into Python: $ python -m venv [directory] This command creates a venv in the specified directory and copies pip into it as well. If you’re unsure what to call the directory: venv is a commonly seen option; it doesn’t leave anyone guessing what it is. A little further in this article, we’ll take a close look at the directory that was just created. But let’s first look at how to activate this virtual environment.

al-baba
  • 43
  • 7