0

First, it works on my work computer, but doesn't work on my home desktop. Second, I've explored several previous answers, with no luck. Perhaps I just didn't read the ONE that has my solution.

I want to run an executable python script from anywhere (it takes one string argument). My solution is to use a bash alias in .bashrc:

I have tried several variants:

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"

None of them work, the respective outputs are:

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

So for a sanity check, I did this:

$ cd ~/projects/tlog
$ ls
logs  prev_log_date  tlog.py

Yep it's there... so does it run?

$ ./tlog.py "TEST"
yadda yadda it worked

Yep, so now:

$ ~/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

Well... what about

$ more ~/projects/tlog/tlog.py
#!/usr/bin/env python
"""
tlog - tlog docstring
"""
...rest of file...

Yep, it's still there. Anyone got an answer for me? For reference:

$ 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
1
  • I'm not sure what is wrong with your aliases, but you could add it to your path. PATH=$PATH:$HOME/projects/tlog Commented Nov 11, 2016 at 4:41

1 Answer 1

2

Looks like you use windows-based python, not cygwin based python

Check for cygwin python installed

ls /bin/python*

if you do not have cygwin python, install it.

If you already have cygwin python installed, then check your PATH variables -- cygwin /bin/ folder must go before windows python folder.

If you really need to use windows python from cygwin... read a lot about 'windows python from cygwin' -- there are tons of glitches, special situations and unpredicted behaviors

Also, you can try such alias: (cannot check it myself)

alias tlog="cmd.exe C:\\Python27\\python.exe -i C:\\cyg\\home\\<my_username>\\projects\\tlog\\tlog.py"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.