./xx.py: line 1: import: command not found

后端 未结 6 1569
不知归路
不知归路 2020-12-03 13:32

I am trying to use this Python urllib2 Basic Auth Problem bit of code to download a webpage content from an URL which requires authentication. The code I am trying is:

6条回答
  •  广开言路
    2020-12-03 14:15

    When you see "import: command not found" on the very first import, it is caused by the parser not using the character encoding matching your py file. Especially when you are not using ASCII encoding in your py file.

    The way to get it right is to specify the correct encoding on top of your py file to match your file character encoding.

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    import os
    

提交回复
热议问题