在mac termin中创建快捷方式

2024-09-29 23:22:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图为mac终端创建一条捷径,这样当我编写“jj”时,终端中使用的以下代码行将运行:

python 5_7_16.py

我的搭档可以为Linux写程序,但他不能为Mac写。他设法把代码的路径写成如下

      FPTH="/Users/kylefoley/PycharmProjects/inference_engine2/inference2/Proofs/5_7_16.py"

当我使用pycharm软件时,这是我在使用python5\u7\u16.py之前使用的前两行代码

cd inference2
cd Proofs

我们已经在正确的位置保存了python文件jj,我们几乎可以让它工作,但还不够

另外,软件有三种模式:输出到excel,输出到django,输出到mysql。由于我不明白的原因,我的搭档认为我们需要在文件中写下什么类型的模式是活动的。我不明白为什么会这样,因为所有这些信息都已经存储在5u7u16文件中了。为了以防万一,这里是python代码的第一行

excel = True
mysql = False

if not excel and not mysql:
    from inference2.models import Define3, Archives, Input
    from inference2 import views
if mysql:
    import os
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    print BASE_DIR
    sys.path.append(BASE_DIR)
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "inference_engine2.settings")
    import django
    django.setup()
    from inference2 import views
    from inference2.models import Define3, Archives, Input

这就是他迄今为止写的东西,我想,我不明白为什么所有这些都是必要的。我想你只需要告诉mac终端你想运行什么代码:

FPTH="/Users/kylefoley/PycharmProjects/inference_engine2/inference2/Proofs/5_7_16.py"

vmysql=$(sed -i ‘’ -E ’s/^mysql = \(.*\)/\1/g’ $FPTH)
vexcel=$(sed —i ‘’ E ’s/^excel = \(.*\)/\1/g’ $FPTH)
echo $vexcel
echo $vmysql
if [ "$vexcel" == "True" ] ; then
echo "Excel"
elif [ "$vmysql" = "True" ] 
then
echo "Mysql"
else
echo "Django"
fi
if [ "$vexcel" = "True" ] ; then
echo "Excel is set”
python $FPTH
elif [ "$vmysql" = "True" ] 
then
echo "Mysql is set”
python $FPTH
else
echo “Django is set”
cd /dUsers/kylefoley/PycharmProjects/inference_engine2
python manage.py runserver
fi

Tags: path代码frompyimportechotrueif
1条回答
网友
1楼 · 发布于 2024-09-29 23:22:36

您需要在.bash_profile文件中添加别名。 有关详细信息,请选中:About .bash_profile, .bashrc, and where should alias be written in?

以下是要遵循的步骤:

# Step 1: Go To home directory
cd 

# Step 2: Edit ".bash_profile" file OR, create if not exists
vi .bash_profile
# In this file add entry at last as:
# alias jj="python ~/inference2/Proofs/5_7_16.py"
#                  ^ OR whatever is the path to file

# Now, close the file

# Step 3: Refresh bash shell environment
source ~/.bash_profile

你现在可以做了


从bash手册页:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The noprofile option may be used when the shell is started to inhibit this behavior.

相关问题 更多 >

    热门问题