繁体   English   中英

如何在 vscode 上安装 web3 而不会出现所有这些问题?

[英]How to install web3 on vscode without having all these issues?

这是我正在尝试运行的代码(来自 Patric 的课程),请考虑这是我第一次进行编码,并且已经尝试了两周来解决这个问题!

从 solcx 导入 compile_standard 从 web3 导入 Web3 导入 json

使用 open("./SimpleStorage.sol", "r") 作为文件: simple_storage_file = file.read()

Solidity 源代码compiled_sol = compile_standard(

 { "language": "Solidity", "sources": {"SimpleStorage.sol": {"content": simple_storage_file}}, "settings": { "outputSelection": { "*": { "*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"] } } }, }, solc_version="0.6.0", )

使用 open("compiled_code.json", "w") 作为文件: json.dump(compiled_sol, file)

获取字节码 bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][

 "bytecode" ]["object"]

得到 abi abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]

连接到 ganach w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545")) chaind_id = 5777

my_address = "0xa1d2a440E4E75bcA442107162DE8C276D637a0eF" 'private_key = os.getenv("0x170ab1d384e1d218ccd8ec332dfa334f8e9980f008043ff04e99a8154322bf06")

在 python SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode) print(SimpleStorage) 中创建合约

我尝试了所有找到的解决方案; 安装了 cyphon,安装了 legacy 但没有任何改变。 这是我在终结者上看到的:

PS C:\Users\raouf\demos\web3_py_simple_storage> pip --version
pip 22.0.4 from C:\Users\raouf\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)
PS C:\Users\raouf\demos\web3_py_simple_storage> python --version
Python 3.10.4
PS C:\Users\raouf\demos\web3_py_simple_storage> pip install web3
Collecting web3
  Using cached web3-5.29.1-py3-none-any.whl (500 kB)
Collecting aiohttp<4,>=3.7.4.post0
  Using cached aiohttp-3.8.1-cp310-cp310-win_amd64.whl (555 kB)
Collecting eth-abi<3.0.0,>=2.0.0b6
  Using cached eth_abi-2.1.1-py3-none-any.whl (27 kB)
Collecting jsonschema<5,>=3.2.0
  Using cached jsonschema-4.5.1-py3-none-any.whl (72 kB)
Collecting eth-utils<2.0.0,>=1.9.5
  Using cached eth_utils-1.10.0-py3-none-any.whl (24 kB)
Collecting eth-hash[pycryptodome]<1.0.0,>=0.2.0
  Using cached eth_hash-0.3.2-py3-none-any.whl (8.8 kB)
Collecting eth-account<0.6.0,>=0.5.7
  Using cached eth_account-0.5.7-py3-none-any.whl (101 kB)
Collecting hexbytes<1.0.0,>=0.1.0
  Using cached hexbytes-0.2.2-py3-none-any.whl (6.1 kB)
Collecting eth-typing<3.0.0,>=2.0.0
  Using cached eth_typing-2.3.0-py3-none-any.whl (6.2 kB)
Collecting websockets<10,>=9.1
  Using cached websockets-9.1-cp310-cp310-win_amd64.whl
Requirement already satisfied: pywin32>=223 in c:\users\raouf\appdata\local\programs\python\python310\lib\site-packages (from web3) (304)
Collecting lru-dict<2.0.0,>=1.1.6
  Using cached lru-dict-1.1.7.tar.gz (10 kB)
  Preparing metadata (setup.py) ... done
Collecting protobuf<4,>=3.10.0
  Using cached protobuf-3.20.1-cp310-cp310-win_amd64.whl (903 kB)
Collecting ipfshttpclient==0.8.0a2
  Using cached ipfshttpclient-0.8.0a2-py3-none-any.whl (82 kB)
Requirement already satisfied: requests<3.0.0,>=2.16.0 in c:\users\raouf\appdata\local\programs\python\python310\lib\site-packages (from web3) (2.27.1)
Collecting multiaddr>=0.0.7
  Using cached multiaddr-0.0.9-py2.py3-none-any.whl (16 kB)
Collecting aiosignal>=1.1.2
  Using cached aiosignal-1.2.0-py3-none-any.whl (8.2 kB)
Collecting async-timeout<5.0,>=4.0.0a3
  Using cached async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting yarl<2.0,>=1.0
  Using cached yarl-1.7.2-cp310-cp310-win_amd64.whl (122 kB)
Collecting attrs>=17.3.0
  Using cached attrs-21.4.0-py2.py3-none-any.whl (60 kB)
Requirement already satisfied: charset-normalizer<3.0,>=2.0 in c:\users\raouf\appdata\local\programs\python\python310\lib\site-packages (from aiohttp<4,>=3.7.4.post0->web3) (2.0.12)
Collecting multidict<7.0,>=4.5
  Using cached multidict-6.0.2-cp310-cp310-win_amd64.whl (27 kB)
Collecting frozenlist>=1.1.1
  Using cached frozenlist-1.3.0-cp310-cp310-win_amd64.whl (33 kB)
Collecting parsimonious<0.9.0,>=0.8.0
  Using cached parsimonious-0.8.1-py3-none-any.whl
Collecting eth-keyfile<0.6.0,>=0.5.0
  Using cached eth_keyfile-0.5.1-py3-none-any.whl (8.3 kB)
Collecting eth-keys<0.4.0,>=0.3.4
  Using cached eth_keys-0.3.4-py3-none-any.whl (21 kB)
Collecting rlp<3,>=1.0.0
  Using cached rlp-2.0.1-py2.py3-none-any.whl (20 kB)
Collecting eth-rlp<2,>=0.1.2
  Using cached eth_rlp-0.3.0-py3-none-any.whl (5.0 kB)
Collecting bitarray<1.3.0,>=1.2.1
  Using cached bitarray-1.2.2.tar.gz (48 kB)
  Preparing metadata (setup.py) ... done
Collecting pycryptodome<4,>=3.6.6
  Using cached pycryptodome-3.14.1-cp35-abi3-win_amd64.whl (1.8 MB)
Collecting cytoolz<1.0.0,>=0.10.1
  Using cached cytoolz-0.11.2.tar.gz (481 kB)
  Preparing metadata (setup.py) ... done
Collecting pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0
  Using cached pyrsistent-0.18.1-cp310-cp310-win_amd64.whl (61 kB)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\raouf\appdata\local\programs\python\python310\lib\site-packages (from requests<3.0.0,>=2.16.0->web3) (2021.10.8)
Requirement already satisfied: idna<4,>=2.5 in c:\users\raouf\appdata\local\programs\python\python310\lib\site-packages (from requests<3.0.0,>=2.16.0->web3) (3.3)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\raouf\appdata\local\programs\python\python310\lib\site-packages (from requests<3.0.0,>=2.16.0->web3) (1.26.9)
Collecting toolz>=0.8.0
  Using cached toolz-0.11.2-py3-none-any.whl (55 kB)
Collecting eth-rlp<2,>=0.1.2
  Using cached eth_rlp-0.2.1-py3-none-any.whl (5.0 kB)
Requirement already satisfied: varint in c:\users\raouf\appdata\local\programs\python\python310\lib\site-packages (from multiaddr>=0.0.7->ipfshttpclient==0.8.0a2->web3) (1.0.2)
Collecting base58
  Using cached base58-2.1.1-py3-none-any.whl (5.6 kB)
Requirement already satisfied: netaddr in c:\users\raouf\appdata\local\programs\python\python310\lib\site-packages (from multiaddr>=0.0.7->ipfshttpclient==0.8.0a2->web3) (0.8.0)
Collecting six
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Building wheels for collected packages: lru-dict, bitarray, cytoolz
  Building wheel for lru-dict (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [5 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'lru' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lru-dict
  Running setup.py clean for lru-dict
  Building wheel for bitarray (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [13 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-310
      creating build\lib.win-amd64-cpython-310\bitarray
      copying bitarray\test_bitarray.py -> build\lib.win-amd64-cpython-310\bitarray
      copying bitarray\test_util.py -> build\lib.win-amd64-cpython-310\bitarray
      copying bitarray\util.py -> build\lib.win-amd64-cpython-310\bitarray
      copying bitarray\__init__.py -> build\lib.win-amd64-cpython-310\bitarray
      running build_ext
      building 'bitarray._bitarray' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for bitarray
  Running setup.py clean for bitarray
  Building wheel for cytoolz (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [53 lines of output]
      [1/5] Cythonizing cytoolz/utils.pyx
      [2/5] Cythonizing cytoolz/dicttoolz.pyx
      [3/5] Cythonizing cytoolz/functoolz.pyx
      [4/5] Cythonizing cytoolz/itertoolz.pyx
      [5/5] Cythonizing cytoolz/recipes.pyx
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-310
      creating build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\compatibility.py -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\_signatures.py -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\_version.py -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\__init__.py -> build\lib.win-amd64-cpython-310\cytoolz
      creating build\lib.win-amd64-cpython-310\cytoolz\curried
      copying cytoolz\curried\exceptions.py -> build\lib.win-amd64-cpython-310\cytoolz\curried
      copying cytoolz\curried\operator.py -> build\lib.win-amd64-cpython-310\cytoolz\curried        
      copying cytoolz\curried\__init__.py -> build\lib.win-amd64-cpython-310\cytoolz\curried        
      copying cytoolz\dicttoolz.pyx -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\functoolz.pyx -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\itertoolz.pyx -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\recipes.pyx -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\utils.pyx -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\cpython.pxd -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\dicttoolz.pxd -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\functoolz.pxd -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\itertoolz.pxd -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\recipes.pxd -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\utils.pxd -> build\lib.win-amd64-cpython-310\cytoolz
      copying cytoolz\__init__.pxd -> build\lib.win-amd64-cpython-310\cytoolz
      creating build\lib.win-amd64-cpython-310\cytoolz\tests
      copying cytoolz\tests\dev_skip_test.py -> build\lib.win-amd64-cpython-310\cytoolz\tests       
      copying cytoolz\tests\test_compatibility.py -> build\lib.win-amd64-cpython-310\cytoolz\tests  
      copying cytoolz\tests\test_curried.py -> build\lib.win-amd64-cpython-310\cytoolz\tests        
      copying cytoolz\tests\test_curried_toolzlike.py -> build\lib.win-amd64-cpython-310\cytoolz\tests
      copying cytoolz\tests\test_dev_skip_test.py -> build\lib.win-amd64-cpython-310\cytoolz\tests  
      copying cytoolz\tests\test_dicttoolz.py -> build\lib.win-amd64-cpython-310\cytoolz\tests      
      copying cytoolz\tests\test_docstrings.py -> build\lib.win-amd64-cpython-310\cytoolz\tests     
      copying cytoolz\tests\test_doctests.py -> build\lib.win-amd64-cpython-310\cytoolz\tests       
      copying cytoolz\tests\test_embedded_sigs.py -> build\lib.win-amd64-cpython-310\cytoolz\tests
      copying cytoolz\tests\test_functoolz.py -> build\lib.win-amd64-cpython-310\cytoolz\tests      
      copying cytoolz\tests\test_inspect_args.py -> build\lib.win-amd64-cpython-310\cytoolz\tests   
      copying cytoolz\tests\test_itertoolz.py -> build\lib.win-amd64-cpython-310\cytoolz\tests      
      copying cytoolz\tests\test_none_safe.py -> build\lib.win-amd64-cpython-310\cytoolz\tests      
      copying cytoolz\tests\test_recipes.py -> build\lib.win-amd64-cpython-310\cytoolz\tests        
      copying cytoolz\tests\test_serialization.py -> build\lib.win-amd64-cpython-310\cytoolz\tests  
      copying cytoolz\tests\test_signatures.py -> build\lib.win-amd64-cpython-310\cytoolz\tests     
      copying cytoolz\tests\test_tlz.py -> build\lib.win-amd64-cpython-310\cytoolz\tests
      copying cytoolz\tests\test_utils.py -> build\lib.win-amd64-cpython-310\cytoolz\tests
      running build_ext
      building 'cytoolz.dicttoolz' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cytoolz
  Running setup.py clean for cytoolz
Failed to build lru-dict bitarray cytoolz
Installing collected packages: lru-dict, bitarray, websockets, toolz, six, pyrsistent, pycryptodome, protobuf, multidict, hexbytes, frozenlist, eth-typing, eth-hash, base58, attrs, async-timeout, yarl, parsimonious, multiaddr, jsonschema, cytoolz, aiosignal, ipfshttpclient, eth-utils, aiohttp, rlp, 
eth-keys, eth-abi, eth-rlp, eth-keyfile, eth-account, web3
  Running setup.py install for lru-dict ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for lru-dict did not run successfully.
  │ exit code: 1
  ╰─> [7 lines of output]
      running install
      C:\Users\raouf\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_ext
      building 'lru' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

根据这一行:

错误:需要 Microsoft Visual C++ 14.0 或更高版本。 使用“Microsoft C++ 构建工具”获取它: https ://visualstudio.microsoft.com/visual-cpp-build-tools/ [结束输出]

您需要安装Microsoft Visual C++ 14.0

暂无
暂无

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

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