0

I have Python 2.7 and 3.5 installed in my Ubuntu. I installed Pika.

Now I can import Pika only in Pyhton 2.7 and not in 3.5 . How can I import Pika from Python 3.5

I have aliased python=python3.5

-Thanks, JMH

4
  • How did you install it, wouldn't a virtualenv not be better? Dec 25 '17 at 20:07
  • Does installation of python-pika and/or python3-pika work for you?
    – N0rbert
    Dec 25 '17 at 20:19
  • The python command should point to python2 (python 2.7). Pointing to python 3.x will break your system quite horribly. Essential system components (including the package manager) rely upon access to the correct version of python.
    – user535733
    Dec 26 '17 at 2:46
  • Initially installed Pika using the command below : sudo -H pip install pika Which I was able to import only in Python 2.7 Later using : sudo -H pip3 install pika Now I am able to import Pika from python 3.5 Regarding the virtualenv, I need to check. I do not know much about the 'virtualenv' concepts as of now. Removed the alias for : python=python3.5. My rephrased question : [I think this is more generic] How do I install any packages in Python that works for multiple versions in the system ? [Like : same single installation of 'pika' works for both Python 2.7 and 3.5]
    – JMH
    Dec 27 '17 at 6:30
1

JMH as you figured it out yourself:

pip3 install package

installs the package for python3 interpreter

and

pip install package

installs the package for python2 interpreter

As of yet, there is no way to install simultaneously for both interpreters using a single command. Hence use pip and pip3 accordingly.

Also it is unwise to alter python aliases. To invoke python3 interpreter use python3 command and for python2 just use python command.

Happy coding!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.