Forums

/usr/bin/env: ‘python\r’: No such file or directory

I am receiving "/usr/bin/env: ‘python\r’: No such file or directory " error while trying "./manage.py migrate" on pythonanywhere bash console.

Please help me to resolve this error.

Thanks

did you by any chance have a manage.py from a windows machine that you then copied over? it seems like there is a rogue \r in the file?

Below is the content of the file manage. py:

!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Test.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

[edit by admin: formatting]

See the screenshot of the file:![enter image description here][1]

https://ibb.co/mCvGMvF

And yes, I have copied the file from my windows as i have developed it locally and now deploying it

There's an error in that file -- it should have this on the first line:

#!/usr/bin/env python

If you look at your one, you'll see that it's missing the "#" as the first character. A "#!" at the start of a file is not a comment, but is rather a magic line that in effect tells Bash which interpreter to use to run the file.

Thanks giles, at the time of screenshot i accidently removed '#' but believe me i have added # and saved it. Now, i am still on the same page. Any help would be appreciated.

I would expect the error to have changed after that -- could you post a screenshot of a console showing the command that you're running and the error that you're getting?

https://ibb.co/fqvjSZy -----Bash error https://ibb.co/cDGbWqp ---------Manage.py file

Sorry for the late reply.

You have a left-over \r at the end of the first line of your manage.py script. Go to the start of the second line, backspace so that it joins the first line and then hit enter. Save it and it should work.

Still facing the same issue

Exactly the same after editing and saving the file?

Yes, you can take the remote session of my pc if you want. I am struggling from the last 3 days.

Could I look into your files and run some experiments using your account? We can do it, but we ask first.

sure, where should i share my credentials with you?

No need.

Here is what I see:

  • Your manage.py had windows line endings. I fixed it.

  • You have postgres database on localhost configured in your settings. You won't be able to migrate on pythonanywhere with that.

You can use some git remote repository to transfer your code between your machine and PythonAnywhere. Git takes care of line endings between operating systems.

Yes, I got you.Thank you so much for your support. I'll take care of the rest

I am stuck with same issue. Any help?

@iamshubh What file is it about? How do you run it? How does it look like?

i cahnged the

"#!/usr/bin/env python "

to

"#!/usr/bin/env python3.8"

it worked

Glad to hear that you made it work!