skip to Main Content

I’m new in this environment and currently learning the basics of Python through YouTube courses. While using VSCode, I always encounter the same problem when I try to use the terminal. The command (like a pip install for ex) won’t run because my users folder name has a space in it.
It shows "C:User<my first name> " is not valid.
Otherwise when I run code with CodeRunner everything works fine.
I’m sorry to not adjoint a screenshot to it it seems I’m not able to.
Is there anyway to fix this?

3

Answers


  1. You can run the command using quotes.

    It’d go something like:

    python "C:UsersMy Userfile.py"
    

    Using quotes should solve your issue. Cheers!

    Login or Signup to reply.
  2. People will probably say:

    • Don’t put spaces in your paths to begin with.
    • Try updating VSCode?

    If you’re running the commands in the terminal, put quotes around the path. E.g., python "path/to/spaced file.py".

    Otherwise, if this is a task that you’re running, simply put "" around ${file} in tasks.json.

    Though, I strongly recommend not using spaces, and replacing with something like - or _, or just a capitalisation rule like camelCase or PascalCase.

    Login or Signup to reply.
  3. If you have successfully set the environment variables and selected the correct interpreter. Then using the pip command directly in the terminal to install the package will not cause an error.

    enter image description here

    If you cannot avoid using folder names that contain spaces, you can install the package in a terminal using a command in a format similar to the one below.

    just an example

    & "c:/Users/Admin/Desktop/My Name/.venv/Scripts/python.exe" -m pip install numpy
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search