1

I have both Python 2 and Python 3 installed on my MacOS (Mojave 10.14.5). When I run my Python 2 code I get:

ImportError: No module named <modulename>

if I install the module with pip install <modulename> command i get:

Requirement already satisfied: <modulename> in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (0.5)

Then same missing package message as before when running the code with Python 2. The command pip2 install <modulename> is not working. How could I install modules for Python 2?

Barbab
  • 266
  • 1
  • 8
  • 1
    this seems to be helpful: https://stackoverflow.com/a/38043109/479251 (see "method 2 from 2019" in the linked answer). – Pac0 Mar 30 '21 at 20:51
  • 1
    This blog post can also be helpful, please try this, even if it's a bit old. https://blog.kinsacreative.com/articles/installing-python-2-and-python-3-alongside-each-ot/ – Pac0 Mar 30 '21 at 21:04

1 Answers1

0

Does this work?

python2 -m pip install <modulename>
  • Unfortunately I get: ```-bash: python2: command not found``` (I am working on terminal) – Barbab Mar 30 '21 at 11:00
  • How do you invoke python2 normally? e.g. if you normally just use "python" does "python -m pip install " work? I don't have a MacOS computer to hand but I guess python2 might still be the default. – David Parry Mar 30 '21 at 11:09
  • ```python --version``` gives ```Python 2.7.10```. To invoke python I simply use ```python .py``` – Barbab Mar 30 '21 at 11:16
  • In that case `python -m pip install ` should work if pip is installed. – David Parry Mar 30 '21 at 12:05
  • with `python -m pip install ` I get `python: can't open file 'pip': [Errno 2] No such file or directory` – Barbab Mar 30 '21 at 12:17
  • Ok, I managed to install the module with `python -m pip install --user the_module`. Now another problem, maybe worst: I need to install the package cvxpy which I think requires at least python 3.7 because It says ` RuntimeError: Python version >= 3.7 required.` Is there any possibility to get around this? – Barbab Mar 30 '21 at 12:42
  • 1
    @Barbab that won't work, indeed it's worse. This installed the python3 version of your library – Pac0 Mar 30 '21 at 20:44