Search code examples
pythonflaskcmdvirtual

'venv\Scripts\activate' is not recognized as an internal or external command, operable program or batch file


There is a similar question but it does not deal with my error:

On trying to install a virtual environment using CMD in the E drive, I used this command:

E:\myproject>venv\Scripts\activate

The error that occurred was:

'venv\Scripts\activate' is not recognized as an internal or external command,
operable program or batch file.

What exactly are the steps required to install flask - the documentation was followed step by step and did not work.

You can trace my steps, and I keep getting stuck here. What am I doing wrong?

E:\>mkdir myproject

E:\>cd myproject

E:\myproject>python3 -m venv venv

E:\myproject>py -3 -m venv venv
Error: Command '['E:\\myproject\\venv\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 3221226505.

E:\myproject>venv\Scripts\activate
'venv\Scripts\activate' is not recognized as an internal or external command,
operable program or batch file.

E:\myproject>

Note: You'll see that I've followed the steps for creating a virtual environment from here: https://flask.palletsprojects.com/en/1.1.x/installation/#virtual-environments

I also tried the following, but also resulting in an error:

E:\myproject>py -3 -m venv venv
Error: Command '['E:\\myproject\\venv\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 3221226505.

E:\myproject>

I tried to enter the venv itself and tried this - again a different error. I think I am missing something very basic.

E:\myproject>cd venv

E:\myproject\venv>venv\Scripts\activate
The system cannot find the path specified.

I also tried: (based on a stackoverflow answer)

E:\myproject\venv>pip install virtualenv

Again, an error.

and

E:\myproject\venv>py -3.8 -m venv venv

still, nothing.

Another point that may be of interest/relevance:

In the E drive ,I installed PYTHON 3.8.3 in the root directory. I am obviously creating the various folders e.g. myproject also in the root directory. E: mkdir myproject

Does the path affect anything? I am now deinstalling and re-installing python.

I am ensuring that I am checking the little tick that says "add python to environment path" (which I hadn't earlier).

On reinstalling: this occured:

E:\>mkdir myproject

E:\>cd myproject

E:\myproject>python --version
Python 3.8.3

E:\myproject>python3 -m venv venv

E:\myproject>venv\Scripts\activate
The system cannot find the path specified.

E:\myproject>

A slightly different error, I note, but still CANNOT FIND THE PATH related.

Finally, I tried creating the dir and venv in the actual folder where python was is installed: Still, an error

E:\>cd Python installation
E:\Python installation>mkdir myproject
E:\Python installation>cd myproject
E:\Python installation\myproject>python3 -m venv venv
E:\Python installation\myproject>venv\Scripts\activate
The system cannot find the path specified.
E:\Python installation\myproject>

Solution

  • Frustrating, as I followed the official flask tutorial and it didn't work. This, however, did:

    I hope someone finds this useful.

    E:\Python installation\myproject>py -m venv env
    E:\Python installation\myproject>env\Scripts\activate
    (env) E:\Python installation\myproject>
    

    Note that in the first step i typed in py -m venv env instead of py -m venv venv (as suggested on the official docs)