Tout d'abord, il fonctionne sur mon ordinateur de travail, mais ne fonctionne pas sur mon bureau à la maison. Deuxièmement, j'ai exploré plusieurs réponses précédentes, sans succès. Peut-être n'ai-je pas lu celui qui a ma solution.Python ne peut pas ouvrir le fichier ... [Errno 2] Aucun fichier ou répertoire
Je veux exécuter un script python exécutable de n'importe où (il prend un argument de chaîne). Ma solution est d'utiliser un alias bash dans .bashrc:
J'ai essayé plusieurs variantes:
alias tlog="~/projects/tlog/tlog.py"
alias tlog="/c/cyg/home/<my_username>/projects/tlog/tlog.py"
alias tlog="C:\\cyg\\home\\<my_username>\\projects\\tlog\\tlog.py"
alias tlog='"/c/cyg/home/<my_username>/projects/tlog/tlog.py"'
alias tlog='"C:\\cyg\\home\\<my_username>\\projects\\tlog\\tlog.py"'
alias tlog="python ~/projects/tlog/tlog.py"
Aucun d'entre eux travaillent, les sorties respectives sont les suivantes:
C:\Python27\python.exe: can't open file '/home/<my_username>/projects/tlog/tlog.py': [Errno 2] No such file or directory
C:\Python27\python.exe: can't open file '/c/cyg/home/<my_username>/projects/tlog/tlog.py': [Errno 2] No such file or directory
bash: C:cyghome<my_username>projectstlogtlog.py: command not found
C:\Python27\python.exe: can't open file '/c/cyg/home/<my_username>/projects/tlog/tlog.py': [Errno 2] No such file or directory
bash: C:\cyg\home\<my_username>\projects\tlog\tlog.py: command not found
C:\Python27\python.exe: can't open file '/home/<my_username>/projects/tlog/tlog.py': [Errno 2] No such file or directory
Donc, pour une santé mentale vérifier, je l'ai fait:
$ cd ~/projects/tlog
$ ls
logs prev_log_date tlog.py
Eh oui, il est là ... donc faut-il courir?
$ ./tlog.py "TEST"
yadda yadda it worked
Eh oui, maintenant:
$ ~/projects/tlog/tlog.py "TEST"
C:\Python27\python.exe: can't open file '/home/<my_username>/projects/tlog/tlog.py': [Errno 2] No such file or directory
Eh bien ... Qu'en est-
$ more ~/projects/tlog/tlog.py
#!/usr/bin/env python
"""
tlog - tlog docstring
"""
...rest of file...
Eh oui, il est toujours là. Quelqu'un a eu une réponse pour moi? Pour référence:
$ ls -la
...more files...
-rwxrwxr-x+ 1 <my_username> <my_username> 6376 Nov 10 17:59 tlog.py
$ cd ..
$ ls -la
...more files...
drwxr-xr-x+ 1 <my_username> <my_username> 0 Nov 10 17:59 tlog
$ python --version
Python 2.7.10
Je ne suis pas sûr de ce qui ne va pas avec vos alias, mais vous pouvez l'ajouter à votre chemin. 'PATH = $ PATH: $ HOME/projets/tlog' – chicks