如何使快捷方式从PATH工作 [英] How to make shortcut work from PATH

查看:90
本文介绍了如何使快捷方式从PATH工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上有两个版本的Python,并希望通过cmd使用它们.我试图为其python.exe创建快捷方式,并将其重命名为python26python33(我还将其位置也添加到了PATH),但是不幸的是,这不起作用.在not recognized as an internal command中调用python26python26.lnk输出.

I have two versions of Python on Windows and want to use them through cmd. I tried to make shortcuts of their python.exe and renaming them to python26 and python33 (I also added their locations to PATH), but unfortunately this does not work. Calling python26 or python26.lnk outputs in not recognized as an internal command.

还有其他方法可以做到吗(例如Linux virtualenv),还是我错过了一些主意?

Is there any other way to do it (like Linux virtualenv), or I missed something in my idea ?

推荐答案

C:\imagaginary_path\下创建一个新的.bat文件,并将其命名为python2.bat.
在bat文件中写入:

Create a new .bat file under C:\imagaginary_path\ and name it python2.bat.
Within the bat file write:

C:\Python26\python.exe %*

然后在C:\imagaginary_path\下创建另一个,并将其命名为python3.bat.
内容:

Then create another one under C:\imagaginary_path\ and name it python3.bat.
With the content:

C:\Python33\python.exe %*

现在从PATH中删除C:\Python26\C:\Python33\,然后将C:\imaginary_path\放在PATH变量中.

Now remove C:\Python26\ and C:\Python33\ from your PATH and instead place C:\imaginary_path\ in your PATH variable.

在那里,Windows将.bat文件视为可执行文件,现在您可以调用python2 test.py 现在,每次按 Ctrl + C 时,都会出现一个提示,询问终止批处理作业?".这很烦人,有几种方法可以解决这个问题,其中一种是您编辑python2.bat使其看起来像这样:

There, Windows treats .bat files as executables, and now you can call python2 test.py Now every time you press Ctrl+C You will get a promt asking "Terminate batch job ?" which is kind of annoying, there's a few alternatives in order to solve this and one being you edit your python2.bat to look like:

start C:\Python26\python.exe %*

这篇关于如何使快捷方式从PATH工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆