pythonvisual-studio-codepippython-3.6macos-catalina

How to install dependencies using pip install in VS Code on macOS Catalina


I created a new virtual environment on VS Code in python 3.6.2 using python3 venv venv and activated it using venv/bin/activate. Then I tried to install speech recognition using pip install speechrecognition but, it give me an error saying:

bash: /Users/naman/Documents/Ai Assistant/assistant/bin/pip: "/Users/naman/Documents/Ai: bad interpreter: No such file or directory

I cannot install anything using pip install in the new virtual environment. Please Help! Im using VS Code on macOS Catalina


Solution

  • You have Python and pip in /Users/naman/Documents/Ai Assistant/assistant/bin/. Unfortunately that path contains a space and Unix (MacOS X in your case) doesn't like spaces in paths to executable files.

    The problem is shebang. Your pip has this as the first line:

    #!/Users/naman/Documents/Ai Assistant/assistant/bin/python
    

    When you execute pip the OS' kernel sees #! and understands it's a script that has to be run with an interpreter. The OS takes the first line and split it by spaces. Here is the problem: the OS tries to run /Users/naman/Documents/Ai as the interpreter and failed.

    My advice is to re-install Python and pip into a directory without spaces in its full path.

    A workaround for your current situation is to run python manually. Either

    python -m pip install speechrecognition
    

    or

    "/Users/naman/Documents/Ai Assistant/assistant/bin/python" -m pip install speechrecognition
    

    Please note quotes — they prevent the command interpreter to split by spaces so that the entire /Users/naman/Documents/Ai Assistant/assistant/bin/python becomes one path to the interpreter. There is no way to use quotes and avoid splitting in the shebang line.