-2

我的 python 安装在 c:\python27 中,我的站点包位于 C:\Python27\Lib\site-packages 中。我无法理解的问题是为什么如果我将一个名为 base-install.py 的脚本放在站点包中并使用它调用它

C:\Users\max>python base-install.py
python: can't open file 'base-install.py': [Errno 2] No such file or directory

第二个问题是我对 virtualenv 有同样的问题。当我创建它并使用 Scripts\activate.bat 激活它时,如果我尝试调用,例如 python django-admin.py(正确安装在 virtenv 的站点包中)我有同样的问题:

(test2) D:\www\test2>python django-admin.py
python: can't open file 'django-admin.py': [Errno 2] No such file or directory

自从 2 小时以来,我一直坚持这一点,我无法找到我搞砸的地方。

4

2 回答 2

1

您将python 模块搜索路径文件系统路径混淆了。

当您键入以下内容时:

C:\Users\max>python base-install.py

python= 这行得通,因为 python 可执行文件 (python.exe) 在您的文件系统路径中。Python 安装程序将 的位置添加python.exe到您的全局文件系统路径中。

base-install.py该文件不在文件系统路径中的任何目录中,也不在max运行命令的目录中,这就是您收到错误的原因。

第二个问题更容易解决。在 Windows 中,脚本被添加到Scripts目录中:

只需这样做:

(test2) D:\www\test2>python Scripts\django-admin.py

于 2012-02-01T12:03:44.967 回答
1

如果您想从其他位置执行该脚本,您应该这样做:

    python -m base-install

这样,如果 base-install.py 在 site-packages 或添加到PYTHONPATH它的任何其他目录中应该可以工作。

于 2012-02-01T12:10:53.323 回答