简体   繁体   English

如何修改我的cygwin环境以使用Strawberry Perl而不是打包的Perl发行版?

[英]How can I modify my cygwin environment to use Strawberry Perl instead of the packaged Perl distribution?

I currently use Strawberry Perl as my primary Perl distribution. 我目前使用Strawberry Perl作为我的主要Perl发行版。 However, I have some applications that make Perl calls through cygwin. 但是,我有一些应用程序可以通过cygwin调用Perl。 These generally fail because they are calling the version of Perl that was packaged with cygwin, and only looking in cygwin's lib folders. 这些通常会失败,因为他们正在调用与cygwin一起打包的Perl版本,并且只查看cygwin的lib文件夹。 How can I modify my cygwin environment to call Strawberry Perl (and use the C:/strawberry/perl/lib dirs) instead? 如何修改我的cygwin环境来调用Strawberry Perl(并使用C:/ strawberry / perl / lib dirs)?

If you remove Perl from cygwin using the setup program it will use Strawberry Perl by default. 如果您使用安装程序从cygwin中删除Perl,它将默认使用Strawberry Perl。

If you are unable to remove Perl from cygwin, you can create a symbolic link to the Perl executable from Strawberry. 如果您无法从cygwin中删除Perl,则可以创建一个指向Strawberry的Perl可执行文件的符号链接。

From a cygwin shell, use the following set of commands: 从cygwin shell中,使用以下命令集:

$ mv /usr/bin/perl /usr/bin/perl-cygwin
$ ln -s /cygdrive/c/strawberry/perl/bin/perl.exe /usr/bin/perl

This is assuming you used the default Strawberry Perl installer. 这假设您使用了默认的Strawberry Perl安装程序。 Update your perl.exe location accordingly if you have it installed somewhere else. 如果已将其安装在其他位置,请相应地更新perl.exe位置。

Check to make sure the link is working properly by checking the Perl version: 通过检查Perl版本检查以确保链接正常工作:

$ perl -v

It should say This is perl, (version) built for MSWin32-x86-multi-thread (or similar) and not built for cygwin-thread-multi-64int . 它应该说这是为MSWin32-x86多线程 (或类似)构建的perl(版本),不是 为cygwin-thread-multi-64int构建的

One good thing I can add is that if you get the right perl to come first in the path, it should handle site-specific CPAN modules you may have installed with strawberry perl running in a CMD shell. 我可以添加的一件好事是,如果你在路径中得到正确的perl,它应该处理你可能已经安装了在CMD shell中运行的草莓perl的特定于站点的CPAN模块。

"which perl" is your friend. “哪个perl”是你的朋友。

If you had trouble with this, you could set the PERL5LIB environment variable, but it shouldn't be necessary. 如果您遇到此问题,可以设置PERL5LIB环境变量,但不一定需要。

I still pass in DOS-style file paths as parameters into the perl script, ie "d:\\data\\myfile.txt", not "/cygdrive/d/data/myfile.txt". 我仍然将DOS样式的文件路径作为参数传递到perl脚本中,即“d:\\ data \\ myfile.txt”,而不是“/cygdrive/d/data/myfile.txt”。 So oddly enough, this mix of path notation works: 奇怪的是,这种路径表示法的组合起作用:

bash> /cygdrive/d/scripts/myscript.pl d:\\data\\myfile.txt bash> /cygdrive/d/scripts/myscript.pl d:\\ data \\ myfile.txt

Many of these are good solutions, but I rather take an easy one that I don't have to modify more than once. 其中许多是很好的解决方案,但我宁愿采取一个简单的解决方案,我不必多次修改。

All you need to do is add/modify a line in your .bashrc file. 您需要做的就是在.bashrc文件中添加/修改一行。

# Prepend strawberry perl to cygwin's path
export PATH=/cygdrive/C/Tools/Perl/perl/bin:$PATH

source .bashrc file from your shell, (or start a new shell) and run your program. 从shell获取.bashrc文件,(或启动一个新shell)并运行您的程序。

source ~/.bashrc
perl script.pl 

You can change your PATH to put the Strawberry directories first. 您可以更改PATH以将Strawberry目录放在第一位。 Strawberry tries to be nice by putting its directories at the end of the PATH. 通过将其目录放在PATH的末尾,草莓试图变得更好。 If you installed from the .zip file, however, it didn't change the PATH at all. 但是,如果从.zip文件安装,则根本不会更改PATH。

You could move /usr/bin/perl, but that's a bad idea since it breaks when cygwin tries to update what it thinks is its perl. 你可以移动/ usr / bin / perl,但这是一个坏主意,因为当cygwin尝试更新它认为是它的perl时,它会中断。 I just had that happen to me this week and used to happen to me on my Mac until I stopped playing with the system setup and installed my own stuff completely separate. 我本周发生了这件事,过去常常在我的Mac上发生,直到我停止使用系统设置并完全独立安装我自己的东西。

If you don't want to mess around with any paths or do anything permanent there is an easy TEMPORARY hack . 如果你不想乱用任何路径或做任何永久性的事情,那么就有一个简单的TEMPORARY hack Type "where perl" at Cygwin sh prompt. 在Cygwin sh提示符下键入“where perl”。 It will list all the Perl.exe it sees in PATH in their order of execution. 它将按照执行顺序列出它在PATH中看到的所有Perl.exe。 Change the names of the ones you don't want to be seen that get listed before the perl you want to use. 更改要在您要使用的perl之前列出的不希望看到的名称。 But DO remember to change them back when you are done or you might have a few problems down the road. 但是你要记得在你完成后改回它们,否则你可能会遇到一些问题。

This is probably not a preferred solution, but you should be able to modify the #! 这可能不是首选解决方案,但您应该能够修改#! line: 线:

#!/cygdrive/c/strawberry/perl/bin/perl5.10.0

I always refer to an explicit location and installation of perl, rather than relying on what is in /usr/bin. 我总是提到perl的显式位置和安装,而不是依赖于/ usr / bin中的内容。

I have two scripts that I use to modify the first line of Perl scripts to whichever Perl is first in my path: rightperl hardcodes to the Perl that is first in my $PATH now , envperl will change the line to #!/usr/bin/env perl so the Perl to use is only picked at the time the script is invoked. 我有我用来修改Perl脚本的第一行取其Perl是第一次在我的道路两个脚本: rightperl会有限制于Perl中是第一次在我的$ PATH 现在envperl !将线路改为#在/ usr / bin中/ env perl所以只能在调用脚本时选择要使用的Perl。 Works really well under Cygwin (and from a Unix shell in general). 在Cygwin(以及一般的Unix shell)下工作得非常好。

我没有附近的cygwin机器所以我无法测试这个,但也许你可以用脚本前端perl命令:转到cygwin下的/ bin并将perl.exe移到其他地方,如perl- org.exe,然后设置一个shell脚本,用相同的参数执行你的另一个perl。

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

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