-2

First of all, to put in context:

  • I have installed Python 3.9 which comes from Visual Studio 2019

  • I have installed Python 3.8 from Microsoft Store which installs it in the path:

    C:\Users\username\AppData\Local\Microsoft\WindowsApps

Now I want to create a virtual environment for Python 3.8 so I can switch to it whenever I need. So I follow below steps (below commands are all executed from path C:\Users\username\AppData\Local):

  1. Installing virtualenv:

    py -3.8 -m pip install virtualenv

enter image description here

  1. Creating new virtual environment for Python 3.8:

    py -3.8 -m virtualenv _venv38.win32

enter image description here

And what's the surprise? Folder _venv38.win32 is not created within the directory I am which is C:\Users\username\AppData\Local

Instead _venv38.win32 is created in:

C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\Local\_venv38.win32

So why? I want it to be created in:

C:\Users\username\AppData\Local\_venv38.win32

which is the path from where I have executed the command (step 2)

Willy
  • 9,848
  • 22
  • 141
  • 284
  • 1
    Please [don’t post images of code, error messages, or other textual data.](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) – tripleee Jan 13 '22 at 12:47
  • Is there a reason you are using the third-party `virtualenv` over the standard `venv`? – tripleee Jan 13 '22 at 12:48
  • @tripleee The only reason is that i googled and see that virtualenv was being used a lot so I decided to use it. Anyway the question here is: Why new virtual environment folder for Python 3.8 is not created in the same directory where I am executing the command? As I have understood from different sites, it creates the virtual environment folder in the same directory where I am but in my case it is not happening. I would like to know why. – Willy Jan 13 '22 at 12:58

1 Answers1

1

use

py -3.8 -m venv _venv38.win32

this will create venv at cwd.

virtualenv has a custom "remote" location for virtual environments somewhere outside your project

alexzander
  • 1,586
  • 1
  • 9
  • 21
  • 1
    [What exactly is current working directory?](https://stackoverflow.com/questions/45591428/what-exactly-is-current-working-directory) – tripleee Jan 13 '22 at 13:00
  • When I execute your command below error is thrown: Error: Command '['C:\\Users\\username\\AppData\\Local\\_venv38.win32\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 106. – Willy Jan 13 '22 at 13:07
  • 1
    in your case it will be: `C:\Users\username\AppData\Local` – alexzander Jan 13 '22 at 13:07
  • I am not joking, honestly I didn't know what cwd means! – Willy Jan 13 '22 at 13:07
  • 1
    why you installed python from microsoft store? really, cmon man... go and install it manually from python.org – alexzander Jan 13 '22 at 13:08
  • 1
    so. try again. install python3.8 from python.org. run `py -3.8 -m pip install --upgrade pip`, then run `py -3.8 -m venv _venv38.win32`. and put your python.exe anywhere you want. – alexzander Jan 13 '22 at 13:09
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/241034/discussion-between-alexzander-and-ralph). – alexzander Jan 13 '22 at 13:12
  • Finally it works. Thx. – Willy Jan 13 '22 at 15:07
  • Installing Python from Microsoft Store was causing problems. I downloaded Python 3.8 from python.org and install it. Now virtual environment is created in the same directory where I am and I execute the command. – Willy Jan 13 '22 at 20:53