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

后端 未结 6 1497
不知归路
不知归路 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:00

    I've experienced the same problem and now I just found my solution to this issue.

    #!/usr/bin/python
    
    import sys
    import os
    
    os.system('meld "%s" "%s"' % (sys.argv[2], sys.argv[5]))
    

    This is the code[1] for my case. When I tried this script I received error message like :

    import: command not found

    I found people talks about the shebang. As you see there is the shebang in my python code above. I tried these and those trials but didn't find a good solution.

    I finally tried to type the shebang my self.

    #!/usr/bin/python
    

    and removed the copied one.

    And my problem solved!!!

    I copied the code from the internet[1].

    And I guess there had been some unseeable(?) unseen special characters in the original copied shebang statement.

    I use vim, sometimes I experience similar problems.. Especially when I copied some code snippet from the internet this kind of problems happen.. Web pages have some virus special characters!! I doubt. :-)

    Journeyer

    PS) I copied the code in Windows 7 - host OS - into the Windows clipboard and pasted it into my vim in Ubuntu - guest OS. VM is Oracle Virtual Machine.

    [1] http://nathanhoad.net/how-to-meld-for-git-diffs-in-ubuntu-hardy

提交回复
热议问题