macos Mac OS X 中有两个版本的 Perl?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3480135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Two versions of Perl in Mac OS X?
提问by purinkle
I've installed the Template module via CPAN on my MacBook Pro and it seemed to install correctly.
我已经通过 CPAN 在我的 MacBook Pro 上安装了模板模块,它似乎安装正确。
But, when I try to run a script that includes the Template module, I get the following:
但是,当我尝试运行包含模板模块的脚本时,我得到以下信息:
Can't locate Template.pm in @INC (@INC contains: /Users/purinkle/Sites/rob/modules /Library/Perl/Updates/5.10.0/darwin-thread-multi-2level /Library/Perl/Updates/5.10.0 /System/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/Perl/5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Network/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.10.0 .) at ./index.pl line 12.
BEGIN failed--compilation aborted at ./index.pl line 12.
在@INC 中找不到 Template.pm(@INC 包含:/Users/purinkle/Sites/rob/modules /Library/Perl/Updates/5.10.0/darwin-thread-multi-2level /Library/Perl/Updates/ 5.10.0 /System/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/ Perl/5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Network/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Extras/5.10。 0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.10.0 .) 在 ./index.pl 第 12 行。
BEGIN 失败——编译在 ./index.pl 第 12 行中止。
I then think that something must have gone wrong during installation and try to install again via CPAN but receive the following message:
然后我认为安装过程中一定出了问题,并尝试通过 CPAN 再次安装,但收到以下消息:
Template is up to date (2.22).
模板是最新的 (2.22)。
I've then ran the instmodsh command to try and find where the module is installed. instmodsh lists these directories:
然后我运行了 instmodsh 命令来尝试查找模块的安装位置。instmodsh 列出了这些目录:
/opt/local/bin
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Manual
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Namespace
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Plugin
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Stash
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Tools
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Tutorial
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/Template/Stash/XS
/opt/local/share/man/man1
/opt/local/share/man/man3
/选择/本地/斌
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Manual
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Namespace
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Plugin
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Stash
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Tools
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/Template/Tutorial
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/Template/Stash/XS
/opt/local/share/man/man1
/opt/local/share/man/man3
It looks like I have some how got two different versions of Perl installed (5.8.9 and 5.10.0) and this is causing confusion between CPAN and other Perl scripts.
看起来我有一些如何安装两个不同版本的 Perl(5.8.9 和 5.10.0),这导致 CPAN 和其他 Perl 脚本之间的混淆。
How can I verify this and how can this issue be resolved?
如何验证这一点以及如何解决此问题?
I've ran the commands
我已经运行了命令
which perl
which cpan
and they both return /opt/local/bin
他们都返回 /opt/local/bin
Running
跑步
find / -name perl
returns
回报
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/opt/local/bin/perl
/opt/local/etc/bash_completion.d/perl
/opt/local/var/macports/software/bash-completion/1.2_0/opt/local/etc/bash_completion.d/perl
/opt/local/var/macports/software/perl5.8/5.8.9_3/opt/local/bin/perl
/opt/local/var/macports/sources/rsync.macports.org/release/ports/perl
/usr/bin/perl
/usr/local/bin/perl
/usr/share/file/magic/perl
查找:/dev/fd/3:不是目录
find: /dev/fd/4: 不是目录
/opt/local/bin/perl
/opt/local/etc/bash_completion.d/perl
/opt/local/var/macports/software/bash-completion/1.2_0/opt/local/etc/bash_completion.d/perl
/opt/local/var/macports/software/perl5.8/5.8.9_3/opt/local/bin/perl
/opt/local/var/macports/sources/rsync.macports.org/release/ports/perl
/usr/bin/perl
/usr/local/bin/perl
/usr/share/file/magic/perl
and
和
find / -name cpan
returns
回报
/opt/local/bin/cpan
/opt/local/var/macports/software/perl5.8/5.8.9_3/opt/local/bin/cpan
/Users/purinkle/.cpan/build/CPAN-1.9402-KtN827/blib/script/cpan
/Users/purinkle/.cpan/build/CPAN-1.9402-KtN827/scripts/cpan
/Users/purinkle/.cpan/build/CPAN-1.9402-zb0AeX/blib/script/cpan
/Users/purinkle/.cpan/build/CPAN-1.9402-zb0AeX/scripts/cpan
/usr/bin/cpan
/opt/local/bin/cpan
/opt/local/var/macports/software/perl5.8/5.8.9_3/opt/local/bin/cpan
/Users/purinkle/.cpan/build/CPAN-1.9402-KtN827/blib/script/cpan
/Users/purinkle/.cpan/build/CPAN-1.9402-KtN827/scripts/cpan
/Users/purinkle/.cpan/build/CPAN-1.9402-zb0AeX/blib/script/cpan
/Users/purinkle/.cpan/build/CPAN-1.9402-zb0AeX/scripts/cpan
/usr/bin/cpan
Running
跑步
perl -e 'print join "\n", @INC'
returns
回报
/Users/purinkle/Sites/rob/modules
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level
/opt/local/lib/perl5/site_perl/5.8.9
/opt/local/lib/perl5/site_perl
/opt/local/lib/perl5/vendor_perl/5.8.9/darwin-2level
/opt/local/lib/perl5/vendor_perl/5.8.9
/opt/local/lib/perl5/vendor_perl
/opt/local/lib/perl5/5.8.9/darwin-2level
/opt/local/lib/perl5/5.8.9
/Users/purinkle/Sites/rob/modules
/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level
/opt/local/lib/perl5/site_perl/5.8.9
/opt/local/lib/perl5/site_perl
/opt/local/lib/perl5/vendor_perl/5.8.9/darwin-2level
/opt/local/lib/perl5/vendor_perl/5.8.9
/opt/local/lib/perl5/vendor_perl
/opt/local/lib/perl5/5.8.9/darwin-2level
/opt/local/lib/perl5/5.8.9
回答by Schwern
OS X ships with two versions of Perl. 5.10.0 is the default, so /usr/bin/perl and /usr/bin/cpan should all talk to 5.10.0.
OS X 附带两个版本的 Perl。5.10.0 是默认值,所以 /usr/bin/perl 和 /usr/bin/cpan 都应该与 5.10.0 对话。
The problem is you have three. /opt/local
indicates a MacPortsinstallation which probably installed Perl as a dependency when you weren't looking. That's /opt/local/bin/perl and its probably the default perl in your path. Check with which perl
. That also means you're probably using MacPorts' cpan, check with which cpan
, and thus installed Template Toolkit into the MacPorts version.
问题是你有三个。 /opt/local
表示MacPorts安装,当您未查看时,该安装可能将 Perl 作为依赖项安装。那是 /opt/local/bin/perl 并且它可能是您路径中的默认 perl。检查与which perl
。这也意味着您可能正在使用 MacPorts 的 cpan,检查which cpan
,从而将模板工具包安装到 MacPorts 版本中。
I'm going to guess either you're running a program with #!/usr/bin/perl
at the top or you're using the built in mod_perl or you're running it as a user who is not you. All of which will reference OS X's default Perl and not your MacPorts install.
我猜你要么#!/usr/bin/perl
在顶部运行一个程序,要么在使用内置的 mod_perl,或者你正在以不是你的用户身份运行它。所有这些都将引用 OS X 的默认 Perl,而不是您的 MacPorts 安装。
Macports has a 5.10 as well as 5.12, but "perl" in Macports is still 5.8. You can install 5.10 in Macports.
Macports 有 5.10 和 5.12,但 Macports 中的“perl”仍然是 5.8。您可以在 Macports 中安装 5.10。
As to how to resolve this... if you're using using mod_perl on that machine, use Macports' Perl. It will be easier to install modules and it will be kept up to date better than the OS version.
至于如何解决这个问题……如果您在那台机器上使用 mod_perl,请使用 Macports 的 Perl。安装模块会更容易,并且会比操作系统版本更好地保持最新状态。
To shield yourself from future confusion, you can add aliases into /usr/local/bin
or ~/bin
to perl, perldoc and cpan to the Perl of your choice. That will prevent something else from installing perl in your path and hiHymaning.
为了避免将来混淆,您可以将别名添加到/usr/local/bin
或添加~/bin
到 perl、perldoc 和 cpan 到您选择的 Perl。这将防止其他东西在你的路径中安装 perl 和劫持。
回答by Dave Sherohman
I went through this process about a month and a half ago when setting up a new MacBook Pro. Getting the MacPorts perl installed, switching to /usr/bin/env perl
, and updating my PATH
(which, from comments on Schwern's answer, sounds like it's about where you are now) was straightforward and reasonably well-documented.
大约一个半月前,我在设置新的 MacBook Pro 时经历了这个过程。安装 MacPorts perl、切换到/usr/bin/env perl
和更新我的PATH
(从 Schwern 的回答中的评论来看,这听起来与您现在所处的位置有关)很简单,而且有据可查。
Figuring out how to get the right perl
to show up first in apache's PATH
, on the other hand, was hellish and involved waytoo much googling interspersed with periods of beating my head against the wall for relief.
搞清楚如何得到正确的perl
在apache的第一显示PATH
,在另一方面,是地狱和参与的方式太多了谷歌搜索穿插着打我的头撞在墙上救济的时期。
So, to spare you that, the answer I eventually found was that you need to add a PATH
key to /System/Library/LaunchDaemons/org.apache.httpd.plist
with the PATH
that you want apache to use. Assuming that you're just as unfamiliar with the .plist format as I was at the time, here's my complete current org.apache.httpd.plist
, which has been working great for me:
因此,饶你,答案我终于找到了,你需要一个补充PATH
键/System/Library/LaunchDaemons/org.apache.httpd.plist
与PATH
您要Apache来使用。假设您和我当时一样不熟悉 .plist 格式,以下是我完整的当前 .plist 格式org.apache.httpd.plist
,它对我来说非常有用:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<true/>
<key>Label</key>
<string>org.apache.httpd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/httpd</string>
<string>-D</string>
<string>FOREGROUND</string>
</array>
<key>OnDemand</key>
<false/>
<key>SHAuthorizationRight</key>
<string>system.preferences</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
</dict>
</plist>
Copy/paste that to your system (or just add the EnvironmentVariables
key and its accompanying dict to your existing file), restart apache, and you should be set. (Unless I misremembered and it was something else that actually got it working for me, but I'm pretty sure this was it.)
将其复制/粘贴到您的系统中(或者只是将EnvironmentVariables
密钥及其随附的 dict 添加到您现有的文件中),重新启动 apache,您应该就设置好了。(除非我记错了,而且实际上是其他原因让它对我有用,但我很确定就是这样。)
回答by Anthony DiSante
There's another solution which seems to me to be much simpler: just install another copy of the Perl module, and install it into the installation where you want to use it. For example, if you have two Perl installations on your system, one in /usr/bin and another in /opt/local/bin, and your cpan command by default installs the module into the /opt/local/bin installation, but your app (Apache or whatever) is looking for the module in the /usr/bin installation instead, then you just need to invoke cpan as "/usr/bin/cpan" when installing the module. That solves the problem without needing to edit your script, or your Apache config, etc.
在我看来,还有另一种解决方案要简单得多:只需安装 Perl 模块的另一个副本,然后将其安装到要使用它的安装中。例如,如果您的系统上有两个 Perl 安装,一个在 /usr/bin 中,另一个在 /opt/local/bin,并且默认情况下您的 cpan 命令会将模块安装到 /opt/local/bin 安装中,但是您的应用程序(Apache 或其他)正在 /usr/bin 安装中查找模块,然后您只需要在安装模块时将 cpan 调用为“/usr/bin/cpan”。无需编辑脚本或 Apache 配置等即可解决问题。
回答by ennuikiller
start with these 2 commands:
从这两个命令开始:
which perl
which cpan
if you get different paths to the executables then there is a good chance you have 2 versions or perl installed. If they are the same then chances are you have the perl @INC configured incorrectly. You can add paths to @INC bny including this in the very beginning of your script (after the shebang):
如果您获得不同的可执行文件路径,那么您很有可能安装了 2 个版本或 perl。如果它们相同,则可能是您的 perl @INC 配置不正确。您可以在脚本的开头(在shebang之后)添加到@INC bny的路径,包括:
BEGIN {
push @INC,"/path/to/cpan/modules";
}
In any case do this:
在任何情况下都这样做:
find / -name perl
find / -name cpan
see what you get. This will tell you if you have multiple versions or not.
看看你得到了什么。这将告诉您是否有多个版本。
回答by DanM
I was running into a similar issue; in my case, the problem was that I'd been running cpan as myself instead of as root, so it was only installing the cpan modules in my user dir, which the global @INC didn't include. Just run 'sudo cpan' instead of 'cpan', install your modules, and they should be loaded in just fine.
我遇到了类似的问题;就我而言,问题是我一直以自己的身份而不是 root 身份运行 cpan,所以它只在我的用户目录中安装了 cpan 模块,全局 @INC 不包括在内。只需运行 'sudo cpan' 而不是 'cpan',安装您的模块,它们应该可以正常加载。
回答by sebbulon
I had the same problem, no idea how it happened. I suspect it somehow happened during an XCode Update. I fixed this by re-installing Perl on my Mac manually. I used the latest version as described here:
我有同样的问题,不知道它是怎么发生的。我怀疑它在 XCode 更新期间以某种方式发生了。我通过在 Mac 上手动重新安装 Perl 解决了这个问题。我使用了此处描述的最新版本:
http://search.cpan.org/~shay/perl/README.macosx
http://search.cpan.org/~shay/perl/README.macosx
curl -O http://www.cpan.org/src/perl-5.26.1.tar.gz
tar -xzf perl-5.26.1.tar.gz
cd perl-5.26.1
./Configure -des -Dprefix=/usr/local/
make
make test
sudo make install