简体   繁体   English

Python 以太坊区块链交易

[英]Python Ethereum Blockchain Transactions

I want to get ethereum block-chain transactions using python.我想使用 python 获取以太坊区块链交易。 I've imported the following libraries:我导入了以下库:

import psycopg2
from web3 import Web3, HTTPProvider
import sys
import pprint

When I run the .py file with python command with sudo like sudo python file.py , I get the following error:当我使用带有 sudo 之类的 python 命令运行.py文件时sudo python file.py ,出现以下错误:

from web3 import Web3, HTTPProvider 
ImportError: No module named web3

And when i run the same python file with python3 with sudo like sudo python3 file.py , I get the following error:当我使用带有 sudo 的 python3 运行同一个 python 文件时sudo python3 file.py ,我收到以下错误:

import psycopg2
ModuleNotFoundError: No module named 'psycopg2'

Operating System: Ubuntu 18.04.2 LTS bionic操作系统: Ubuntu 18.04.2 LTS 仿生

python -V: Python 3.6.5:: Anaconda, Inc. python -V: Python 3.6.5:: Anaconda, Inc.

python3 -V: Python 3.6.5:: Anaconda, Inc. python3 -V: Python 3.6.5:: Anaconda, Inc.

I have tried lot of commands to install web3 and psycopg2 but all vain.我已经尝试了很多命令来安装 web3 和 psycopg2 但都是徒劳的。

In order to use such libraries you have to install them. 为了使用这些库,您必须安装它们。

You can do that by using pip : 您可以使用pip做到这一点

sudo apt install python3-pip
pip3 install psycopg2

Some additional actions could be necessary based on which library you are trying to install. 根据您要安装的库,可能需要执行一些其他操作。

I had some issues as well with the web3 installation.我在 web3 安装方面也遇到了一些问题。 After hours of searching for an answer, downloading the "Visual Studio Build Tools 2019" and running my venv again after that, finally solved my problem.经过几个小时的寻找答案,下载“Visual Studio Build Tools 2019”并在此之后再次运行我的 venv,终于解决了我的问题。 Hope this can help out.希望这能有所帮助。

I also installed Cython for python我还为 python 安装了 Cython

Usually, Anaconda installs its own version of Python in a location that is different from the location installed on your system.通常,Anaconda 会在与您系统上安装的位置不同的位置安装自己的 Python 版本。

Try executing the pip install <module_name> commands in Anaconda shell ( and not the unix shell )尝试在 Anaconda shell(而不是 unix shell)中执行pip install <module_name>命令

One way to identify that it is an Anaconda shell, is that it will would have created a virtual environment and enabled it in the shell window for you.识别它是 Anaconda shell 的一种方法是,它会创建一个虚拟环境并在 shell 窗口中为您启用它。

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

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