0

I have Perl v5.10.1 installed on my CentOS 6 linux box. However, when I try to import perl in the python terminal, I get an ImportError.

>>>import perl
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: No module named perl

I had a similar issue earlier with Gnuplot, but that was resolved by simply installing another package. ImportError for Gnuplot in python terminal

I cannot figure out what is wrong.

Please help. Thanks.

Community
  • 1
  • 1
aman
  • 121
  • 1
  • 4
  • 12
  • does the perl python module install automatically when you install perl ? try checking if the perl module path is available in sys.path – HaseebR7 Apr 20 '15 at 07:17
  • What are you trying to do? You want to work with written in Perl functions/objects from python? – kvorobiev Apr 20 '15 at 07:18
  • 1
    This could be useful: http://stackoverflow.com/questions/4002344/how-can-i-use-a-perl-module-from-python – slackmart Apr 20 '15 at 07:19
  • Yes. I have some scripts in python which are trying to import the perl package and use some functions from the package. – aman Apr 20 '15 at 07:20
  • Python doesn't come with a module named `perl`. There appear to be at least three third-party packages for interacting with perl that might install modules named `perl`. Do you have any idea which one you want? – abarnert Apr 20 '15 at 07:38
  • I have no idea. I am working on a script written by somebody else. The script was written a few months back. – aman Apr 20 '15 at 07:43
  • Well, what machine did the script run on? Someone had to have installed the module on that machine. Do you have access to it? – abarnert Apr 20 '15 at 07:45
  • Yes. I do have access to the machine. – aman Apr 20 '15 at 07:55
  • abarnert, could you list the third-party packages? – aman Apr 20 '15 at 09:59
  • On the machine that has a module named `perl`, in Python, try `import perl; print perl.__file__`. If we're lucky, it's a .py file that wraps a compiled module, not just a raw compiled module. By looking at the first few lines of that .py file, it should be easier to find it online. – abarnert Apr 22 '15 at 17:26
  • Also, what version of Python does that other machine have? If it's using 2.3, it could also be using the ancient PyPerl module that may not have ever been ported to 2.6. That means you'd either have to install 2.3, port PyPerl yourself, or adapt the script to use a different solution. – abarnert Apr 22 '15 at 17:29
  • The other machine uses python 2.6.6. – aman Apr 24 '15 at 07:25
  • @abarnert Also, I tried printing 'perl.__file__'. It turned out to be a .so file. – aman Apr 24 '15 at 07:27
  • As a last resort, if the two machines have the same OS and architecture, you can always just copy over `perl.so` (or whatever it's called). – abarnert Apr 24 '15 at 07:55

1 Answers1

0

First you have to download pyperl package and then install it.
Download link http://www.felix-schwarz.name/files/opensource/pyperl/

  1. Download the package
  2. unzip it if it is zipped
  3. open cmd and cd into the directory containing setup.py
  4. type in python setup.py install
Himanshu dua
  • 2,496
  • 1
  • 20
  • 27
  • Are you sure this is the module he wants? It's not on PyPI, the page you linked says it's outdated (since 2005), it doesn't seem to built with Python 2.7 (or 3.4, unsurprisingly) against Perl 5.18.2, at least for 64-bit OS X or Fedora Linux… – abarnert Apr 20 '15 at 07:33
  • Also, the instructions say pretty clearly that there are other steps you have to do before the `setup.py`, especially installing the `Python::Object` module for perl. – abarnert Apr 20 '15 at 07:33
  • There's a newer package called `PythonPerl` that _is_ on PyPI, and its module appears to be named `perl`… but that won't build for me either on 2.7… (in fact, it won't even download; it thinks the right package version for Python 2.7 is the empty string, which it can't find…). – abarnert Apr 20 '15 at 07:36
  • @abarnet This is no official version of pyperl. this is just a patch – Himanshu dua Apr 20 '15 at 07:37
  • Yes, I see that the patch says there _is_ no official version. It also says it probably won't work for you since it hasn't been updated since Python 2.3, although maybe some other patches might help. So… does this actually work for you, or anyone else you know, on 2.7 (or whichever version CentOS 6 comes with)? – abarnert Apr 20 '15 at 07:43
  • This didn't help. There are a lot of errors when I'm trying to run the setup.py file. Also, my copy of CentOS has python 2.6.6 – aman Apr 20 '15 at 09:19
  • @aman you have to install pyperl.There is no official version available right now.You have to search for stable pypearl version. – Himanshu dua Apr 20 '15 at 11:38
  • @himanshu: If (as I suspect) there is no stable version of PyPerl anywhere, or any version that works with 2.6, that doesn't help very much. (It also doesn't help if the script wants `python-perl` instead of `pyperl`, etc.). – abarnert Apr 22 '15 at 17:28