简体   繁体   English

如何使用cygwin终端在Windows机器上安装python?

[英]How do I install python on a windows machine using a cygwin terminal?

I am trying to install python through cygwin on a windows machine in order to make use of a statistical program that can only be implemented using python in a linux environment. 我试图在Windows机器上通过cygwin安装python,以便利用只能在linux环境中使用python实现的统计程序。

I have run setup-x86_64.exe and installed all python related cygwin packages in an attempt to install python, but when I open a terminal and type python I just get 我已经运行setup-x86_64.exe并安装了所有与python相关的cygwin软件包,以尝试安装python,但是当我打开终端并键入python我得到了

$ python
-bash: python: command not found

which is the same for all python commands I try so clearly the installation has not occurred. 这与我尝试的所有python命令相同,因此很明显没有发生安装。 However, I have found a path to Python-2.7.9 which appears to contain the files required to build python from source. 但是,我找到了Python-2.7.9的路径,该路径似乎包含从源代码构建python所需的文件。

When I run ./configure it is successful, but when I then input make it fails due to: 当我运行./configure它是成功的,但是当我再输入make它由于失败:

File "build/temp.cygwin-1.7.35-x86_64-2.7/libffi/fficonfig.py", line 33, in   <module>                                                                               
ffi_sources += ffi_platforms['X86_WIN64']
KeyError: 'X86_WIN64'
Makefile:488: recipe for target 'sharedmods' failed
make: *** [sharedmods] Error 1

Anyone know why make won't work? 有人知道为什么make无效吗?

The options in ./configure --help are unfamiliar to me, could any of these options allow for successful installation? ./configure --help中的选项对我来说是陌生的,这些选项中的任何一个都可以成功安装吗?

Any ideas would be greatly appreciated, thank you. 任何想法将不胜感激,谢谢。

Cygwin comes with an installer, called setup.exe or setup-x86_64.exe . Cygwin带有一个名为setup.exesetup-x86_64.exe Just run it and type python to the search box. 只需运行它,然后在搜索框中输入python Then let it install it for you. 然后让它为您安装。

python language interpreter is the basic package you need. python language interpreter是您需要的基本软件包。

Since building Python from source was said to be a bad idea, I assumed my Cygwin was broken. 由于据说从源代码构建Python是一个坏主意,因此我认为Cygwin已损坏。 I attempted to uninstall Cygwin following the instructions on the Cygwin website, but I was unable to remove it due to permission difficulties (I use a university-supplied Windows machine). 我尝试按照Cygwin网站上的说明卸载Cygwin,但由于权限困难,我无法将其删除(我使用的是大学提供的Windows计算机)。 My last resort was to run the Cygwin installation wizard setup-x86_64.exe and uninstall all packages, then run the wizard once more and select the necessary packages again as if starting from new. 我的最后setup-x86_64.exe是运行Cygwin安装向导setup-x86_64.exe并卸载所有软件包,然后再次运行该向导并再次选择必要的软件包,就像从新安装一样。 Miraculously, installing the required packages from scratch solved the problem and I am now running Python through my Cygwin terminal with no errors. 奇迹般地,从头开始安装所需的软件包解决了该问题,现在我可以通过Cygwin终端运行Python,没有任何错误。

So, this question is 3 years old, but this error still happens with most recent versions of Python 2 (tested with 2.7.13 and 2.7.15 ) 因此,这个问题已有3年历史了,但是对于最新版本的Python 2(经2.7.132.7.15测试),仍然会发生此错误。

I was able to get python to build by modifying the following file in the build directory. 我可以通过修改build目录中的以下文件来构建python。

--- build/temp.cygwin-2.11.1-x86_64-2.7/libffi/fficonfig.py~    2018-11-03 14:51:53.290000000 -0400
+++ build/temp.cygwin-2.11.1-x86_64-2.7/libffi/fficonfig.py     2018-11-03 14:53:41.793000000 -0400
@@ -9,6 +9,7 @@
     'X86': ['src/x86/ffi.c', 'src/x86/sysv.S', 'src/x86/win32.S'],
     'X86_FREEBSD': ['src/x86/ffi.c', 'src/x86/freebsd.S'],
     'X86_WIN32': ['src/x86/ffi.c', 'src/x86/win32.S'],
+    'X86_WIN64': ['src/x86/ffi.c', 'src/x86/win64.S'],
     'SPARC': ['src/sparc/ffi.c', 'src/sparc/v8.S', 'src/sparc/v9.S'],
     'ALPHA': ['src/alpha/ffi.c', 'src/alpha/osf.S'],
     'IA64': ['src/ia64/ffi.c', 'src/ia64/unix.S'],

The source files, in particular src/x86/win64.S , are present in the source tree. 源文件(特别是src/x86/win64.S位于源树中。 For some reason, ./configure does not seem to be properly adding the option to the dictionary in the fficonfig.py file, which causes the KeyError posted in the question. 由于某种原因, ./configure似乎没有正确地将选项添加到fficonfig.py文件中的字典中,这会导致在问题中发布fficonfig.py After making this modification, make and make install completed successfully and I was able to install an alternate version of python in addition to the normal Cygwin package. 进行此修改后, makemake install成功完成,除了正常的Cygwin软件包之外,我还能够安装python的替代版本。

I'm not yet sure why this happens, but I thought I would attempt to provide a solution to the question actually asked rather than just telling the asker to install a pre-compiled version using the package manager. 我还不确定为什么会发生这种情况,但是我想我会尝试提供一个解决实际问题的方法,而不是仅仅告诉发问者使用软件包管理器来安装预编译的版本。

If you want to run Python on Cygwin, you might need to build it from source. 如果要在Cygwin上运行Python,则可能需要从源代码构建它。

  • download the source 下载源
  • unpack it to the directory you could delete later, eg: build 将其解压缩到您以后可以删除的目录中,例如: build
  • run Cygwin, type: cd /path/to/build 运行Cygwin,键入: cd /path/to/build
  • run ./configure --help and read the help about the options you'll need 运行./configure --help并阅读有关所需选项的帮助
  • ./configure #options
  • make

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

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