简体   繁体   English

如何为 python3 安装对流层?

[英]How to install troposphere for python3?

I'm running macOS version 11.0.1 .我正在运行macOS版本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我正在尝试导入一个名为troposphere的模块我安装了Python2.7Python3.9.1当我尝试使用Python2.7导入对流层时

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

It does work.它确实有效。 But when I try to import the same using Python3.9.1 like但是当我尝试使用Python3.9.1导入相同的内容时

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

It throws error like this它会抛出这样的错误

ModuleNotFoundError: No module named 'troposphere'

What should I do?我应该怎么办? Please help请帮忙

Chek if the module was depreciated检查模块是否折旧

it is because the python interpreter you use to run your code doesn't have troposphere installed.这是因为您用于运行代码的 python 解释器没有安装对流层。

Managing multiple Python version on the same computer is tricky, But I will try to explain it.在同一台计算机上管理多个 Python 版本很棘手,但我会尝试解释一下。

I assume that you are using python your_script.py to run your code, and pip install troposphere to install package right?我假设您使用python your_script.py来运行您的代码,并pip install troposphere来安装 package 对吗? But think of this, how does your system know exactly which python you are running and which python to install package?但是想想这个,你的系统怎么知道你在运行哪个 python 和哪个 python 安装 package? Here's how to check the full path of your python command and pip command.这是检查 python 命令和 pip 命令的完整路径的方法。

  1. type python command enter python console键入python命令进入 python 控制台
  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. 3. 稍微上下导航,你会发现一个 bin 文件夹包括bin/python这是你的解释器和bin/pip这是你的 pip 命令。 And there's a lib/site-packages folder, this is where third party library been installed to. 还有一个lib/site-packages文件夹,这是安装第三方库的地方。 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. 4. 如果看到导入错误,使用上述方法找到 python 解释器并检查 site-packages 文件夹,很可能其中没有这样的troposphere文件夹。 Then you need to use the full path of the <path-to>/bin/pip to install troposphere. 然后您需要使用<path-to>/bin/pip的完整路径来安装对流层。 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.如果您使用的是自制软件或从www.python.org下载的 python 安装程序,那么您的系统可能已经搞砸了。 The recommended way to manage multiple Python version is to use pyenv https://github.com/pyenv/pyenv .管理多个 Python 版本的推荐方法是使用 pyenv https://github.com/pyenv/pyenv It allows you to install any python version and easy to delete them.它允许您安装任何 python 版本并轻松删除它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM