Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"bad interpreter: No such file or directory" error if virtual env is in a folder with whitespaces #496

Closed
ulf1 opened this issue Nov 23, 2019 · 5 comments

Comments

@ulf1
Copy link

ulf1 commented Nov 23, 2019

replicate the error

(1) install a virtual env in a folder with whitespaces

mkdir -p "${HOME}/folder with whitespaces/"
cd "${HOME}/folder with whitespaces/"

python3 -m venv .venv
source .venv/bin/activate
pip install uvicorn fastapi

(2) main.py

from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
    return {"Hello": "World"}

(3) Try to start server

uvicorn main:app --reload

Error message

-bash: /Users/uh/folder with whitespaces/.venv/bin/uvicorn: "/Users/uh/folder: bad interpreter: No such file or directory

my guess

I guess you are using something like

filepath=${filepath}

instead of

filepath="${filepath}"

somewhere

@tomchristie
Copy link
Member

This didn't replicate for me.
The "bad interpreter" error makes it look like a shell issue occuring before the python interpreter/uvicorn is even started.

@ulf1
Copy link
Author

ulf1 commented Nov 26, 2019

It might depend on the computer used.
I use MacOS.

I replicated the error in a debian docker container too.
https://github.com/ulf1/bugreport-uvicorn

Feel free to try it with any other OS.

@tomchristie
Copy link
Member

Right, but what you’re showing me there isn’t a Python traceback. Not at all clear that it’s a uvicorn issue rather than some other environment problem. It’d be worth installing other python based command line tools too, and trying those for comparison.

@ulf1
Copy link
Author

ulf1 commented Nov 27, 2019

The cause of the problem is a shebang with whitespaces.
If you install a virtual env in a folder with whitespace,
and install uvicorn into the this virtual env,
then the ../bin/uvicorn script would have shebang like this.

#!"/Users/usernamename/folder with whitespaces/venvname/bin/python3"
...

It seems that the python project had this issue for years (see virtualenv, issue 53) and fixed it somehow.

@tomchristie
Copy link
Member

Ok, thanks. That script isn’t related by uvicorn. You might want to make sure you’ve got recent pip and virtual events versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants