0

I'm running macOS version 11.0.1. I'm trying to import a module called troposphere I have Python2.7 as well as Python3.9.1 installed When I try to import troposphere using Python2.7 like

#!/usr/bin/python
from troposphere import Template

It does work. But when I try to import the same using Python3.9.1 like

#!/usr/bin/python3
from troposphere import Template

It throws error like this

ModuleNotFoundError: No module named 'troposphere'

What should I do? Please help

Red Bottle
  • 2,839
  • 4
  • 22
  • 59

2 Answers2

0

it is because the python interpreter you use to run your code doesn't have troposphere installed.

Managing multiple Python version on the same computer is tricky, But I will try to explain it.

I assume that you are using python your_script.py to run your code, and pip install troposphere to install package right? But think of this, how does your system know exactly which python you are running and which python to install package? Here's how to check the full path of your python command and pip command.

  1. type python command enter python console
  2. then type this:

import sys

print(sys.executable)
3. navigate up and down little bit, you will find a bin folder include bin/python which is your interpreter and bin/pip which is your pip command. And there's a lib/site-packages folder, this is where third party library been installed to. 4. if you see import error, use the above method to locate the python interpreter and check the site-packages folder, most likely there's no such troposphere folder in it. Then you need to use the full path of the <path-to>/bin/pip to install troposphere. Then your problem is solved.

If you are using home brew or the python installer download from www.python.org, your system probablly already messed up. The recommended way to manage multiple Python version is to use pyenv https://github.com/pyenv/pyenv. It allows you to install any python version and easy to delete them.

MacSanhe
  • 2,212
  • 6
  • 24
  • 32
-1

Chek if the module was depreciated

  • In the future, until you have enough reputation, please try not to add incomplete answers and instead put things like this as comments. – darkspine Jan 06 '21 at 06:41