简体   繁体   English

Bash别名不适用于Python脚本

[英]Bash alias not working for Python script

Trying to set a Bash alias in order to run a Python script for Pygame. 尝试设置Bash别名,以便为Pygame运行Python脚本。 I have the android.py acript in, /usr/local/bin/pgs4a-0.9.6/andoid.py . 我在/usr/local/bin/pgs4a-0.9.6/andoid.pyandroid.py抄写。

Bash alias: alias pyg='python /usr/local/bin/pgs4a-0.9.6/android.py' Bash别名: alias pyg='python /usr/local/bin/pgs4a-0.9.6/android.py'

When I run python android.py when I am in the folder in executes just fine, but when I do it from any other folder or using the alias, I get the following error. 当我在文件夹中运行python android.py时,执行起来很好,但是当我从任何其他文件夹或使用别名进行操作时,出现以下错误。

pyg
Traceback (most recent call last):
  File "/usr/local/bin/pgs4a-0.9.6/android.py", line 11, in <module>
    import interface
ImportError: No module named interface

Can anybody explain to me why this is? 有人可以向我解释为什么吗?

Try this: 尝试这个:

alias pyg='PYTHONPATH=/usr/local/bin/pgs4a-0.9.6 python /usr/local/bin/pgs4a-0.9.6/android.py'

That is, set your $PYTHONPATH environment variable to contain the directory with the code. 也就是说,将$ PYTHONPATH环境变量设置为包含带有代码的目录。 You may need to adjust the PYTHONPATH to some other location, depending on where your interface package actually resides. 您可能需要将PYTHONPATH调整到其他位置,具体取决于您的interface包实际所在的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM