numpy 1.7中 f2py示例和说明文档

本文介绍了如何使用f2py将Fortran代码转换为Python模块,包括基本用法、改进接口及高级技巧等内容。

numpy 1.7中 f2py示例和说明文档,主要是介绍如何将fortran转为python模块,如下:

f2py

F2py allows you to automatically construct an extension module that interfaces to routines in Fortran 77/90/95 code. It has the ability to parse Fortran 77/90/95 code and automatically generate Python signatures for the subroutines it encounters, or you can guide how the subroutine interfaces with Python by constructing an interface-definition-file (or modifying the f2py-produced one).

Creating source for a basic extension module

Probably the easiest way to introduce f2py is to offer a simple example. Here is one of the subroutines contained in a file named add.f:

C
      SUBROUTINE ZADD(A,B,C,N)
C
      DOUBLE COMPLEX A(*)
      DOUBLE COMPLEX B(*)
      DOUBLE COMPLEX C(*)
      INTEGER N
      DO 20 J = 1, N
         C(J) = A(J)+B(J)
 20   CONTINUE
      END

This routine simply adds the elements in two contiguous arrays and places the result in a third. The memory for all three arrays must be provided by the calling routine. A very basic interface to this routine can be automatically generated by f2py:

f2py -m add add.f

You should be able to run this command assuming your search-path is set-up properly. This command will produce an extension module named add module.c in the current directory. This extension module can now be compiled and used from Python just like any other extension module.

Creating a compiled extension module

You can also get f2py to compile add.f and also compile its produced extension module leaving only a shared-library extension file that canbe imported from Python:

f2py -c -m add add.f

This command leaves a file named add.{ext} in the current directory(where {ext} is the appropriate extension for a python extension module on your platform — so, pyd, etc. ). This module may then be imported from Python. It will contain a method for each subroutine inadd (zadd, cadd, dadd, sadd). The docstring of each method contains nformation about how the module method may be called:

>>> import add
>>> print add.zadd.__doc__
zadd - Function signature:
  zadd(a,b,c,n)
Required arguments:
  a : input rank-1 array('D') with bounds (*)
  b : input rank-1 array('D') with bounds (*)
  c : input rank-1 array('D') with bounds (*)
  n : input int

Improving the basic interface

The default interface is a very literal translation of the fortran code into Python. The Fortran array arguments must now be NumPy arrays and the integer argument should be an integer. The interface will attempt to convert all arguments to their required types (and shapes)and issue an error if unsuccessful. However, because it knows nothing about the semantics of the arguments (such that C is an output and n should really match the array sizes), it is possible to abuse this function in ways that can cause Python to crash. For example:

>>> add.zadd([1,2,3],[1,2],[3,4],1000)
will cause a program crash on most systems. Under the covers, thelists are being converted to proper arrays but then the underlying add loop is told to cycle way beyond the borders of the allocated memory.

In order to improve the interface, directives should be provided. This is accomplished by constructing an interface definition file. It is usually best to start from the interface file that f2py can produce(where it gets its default be havior from). To get f2py to generate the interface file use the -h option:

f2py -h add.pyf -m add add.f
This command leaves the file add.pyf in the current directory. The section of this file corresponding to zadd is:

subroutine zadd(a,b,c,n) ! in :add:add.f
   double complex dimension(*) :: a
   double complex dimension(*) :: b
   double complex dimension(*) :: c
   integer :: n
end subroutine zadd
By placing intent directives and checking code, the interface can becleaned up quite a bit until the Python module method is both easierto use and more robust.

subroutine zadd(a,b,c,n) ! in :add:add.f
   double complex dimension(n) :: a
   double complex dimension(n) :: b
   double complex intent(out),dimension(n) :: c
   integer intent(hide),depend(a) :: n=len(a)
end subroutine zadd
The intent directive, intent(out) is used to tell f2py that c is an output variable and should be created by the interface before being passed to the underlying code. The intent(hide) directive tells f2pyto not allow the user to specify the variable, n, but instead toget it from the size of a. The depend( a ) directive is necessary to tell f2py that the value of n depends on the input a (so that it won’t try to create the variable n until the variable a is created).

The new interface has docstring:

>>> print add.zadd.__doc__
zadd - Function signature:
  c = zadd(a,b)
Required arguments:
  a : input rank-1 array('D') with bounds (n)
  b : input rank-1 array('D') with bounds (n)
Return objects:
  c : rank-1 array('D') with bounds (n)
Now, the function can be called in a much more robust way:

>>> add.zadd([1,2,3],[4,5,6])
array([ 5.+0.j,  7.+0.j,  9.+0.j])
Notice the automatic conversion to the correct format that occurred.

Inserting directives in Fortran source

The nice interface can also be generated automatically by placing the variable directives as special comments in the original fortran code.Thus, if I modify the source code to contain:

C
      SUBROUTINE ZADD(A,B,C,N)
C
CF2PY INTENT(OUT) :: C
CF2PY INTENT(HIDE) :: N
CF2PY DOUBLE COMPLEX :: A(N)
CF2PY DOUBLE COMPLEX :: B(N)
CF2PY DOUBLE COMPLEX :: C(N)
      DOUBLE COMPLEX A(*)
      DOUBLE COMPLEX B(*)
      DOUBLE COMPLEX C(*)
      INTEGER N
      DO 20 J = 1, N
         C(J) = A(J) + B(J)
 20   CONTINUE
      END
Then, I can compile the extension module using:

f2py -c -m add add.f
The resulting signature for the function add.zadd is exactly the same one that was created previously. If the original source code had contained A(N) instead of A(*) and so forth with B and C, then Icould obtain (nearly) the same interface simply by placing the INTENT(OUT) :: C comment line in the source code. The only differenceis that N would be an optional input that would default to the length of A.

A filtering example

For comparison with the other methods to be discussed. Here is another example of a function that filters a two-dimensional array of double precision floating-point numbers using a fixed averaging filter. The advantage of using Fortran to index into multi-dimensional arrays should be clear from this example.

      SUBROUTINE DFILTER2D(A,B,M,N)
C
      DOUBLE PRECISION A(M,N)
      DOUBLE PRECISION B(M,N)
      INTEGER N, M
CF2PY INTENT(OUT) :: B
CF2PY INTENT(HIDE) :: N
CF2PY INTENT(HIDE) :: M
      DO 20 I = 2,M-1
         DO 40 J=2,N-1
            B(I,J) = A(I,J) +
     $           (A(I-1,J)+A(I+1,J) +
     $            A(I,J-1)+A(I,J+1) )*0.5D0 +
     $           (A(I-1,J-1) + A(I-1,J+1) +
     $            A(I+1,J-1) + A(I+1,J+1))*0.25D0
 40      CONTINUE
 20   CONTINUE
      END
This code can be compiled and linked into an extension module named filter using:

f2py -c -m filter filter.f
This will produce an extension module named filter.so in the current directory with a method named dfilter2d that returns a filteredversion of the input.

Calling f2py from Python

The f2py program is written in Python and can be run from inside your module. This provides a facility that is somewhat similar to the use of weave.ext_tools described below. An example of the final interface executed using Python code is:

import numpy.f2py as f2py
fid = open('add.f')
source = fid.read()
fid.close()
f2py.compile(source, modulename='add')
import add
The source string can be any valid Fortran code. If you want to save the extension-module source code then a suitable file-name can be provided by the source_fn keyword to the compile function.

Automatic extension module generation

If you want to distribute your f2py extension module, then you only need to include the .pyf file and the Fortran code. The distutils extensions in NumPy allow you to define an extension module entirely in terms of this interface file. A valid setup.py file allowing distribution of the add.f module (as part of the package f2py_examples so that it would be loaded as f2py_examples.add) is:

def configuration(parent_package='', top_path=None):
    from numpy.distutils.misc_util import Configuration
    config = Configuration('f2py_examples',parent_package, top_path)
    config.add_extension('add', sources=['add.pyf','add.f'])
    return config

if __name__ == '__main__':
    from numpy.distutils.core import setup
    setup(**configuration(top_path='').todict())


 
  

Installation of the new package is easy using:

python setup.py install
assuming you have the proper permissions to write to the main site-packages directory for the version of Python you are using. For theresulting package to work, you need to create a file named __init__.py(in the same directory as add.pyf). Notice the extension module is defined entirely in terms of the “add.pyf” and “add.f” files. The conversion of the .pyf file to a .c file is handled by numpy.disutils.

Conclusion

The interface definition file (.pyf) is how you can fine-tune theinterface between Python and Fortran. There is decent documentationfor f2py found in the numpy/f2py/docs directory where-ever NumPy isinstalled on your system (usually under site-packages). There is alsomore information on using f2py (including how to use it to wrap Ccodes) athttp://www.scipy.org/Cookbook under the “Using NumPy withOther Languages” heading.

The f2py method of linking compiled code is currently the mostsophisticated and integrated approach. It allows clean separation ofPython with compiled code while still allowing for separatedistribution of the extension module. The only draw-back is that itrequires the existence of a Fortran compiler in order for a user toinstall the code. However, with the existence of the free-compilersg77, gfortran, and g95, as well as high-quality commerical compilers,this restriction is not particularly onerous. In my opinion, Fortranis still the easiest way to write fast and clear code for scientificcomputing. It handles complex numbers, and multi-dimensional indexingin the most straightforward way. Be aware, however, that some Fortrancompilers will not be able to optimize code as well as good hand-written C-code.


Defaulting to user installation because normal site-packages is not writeable Collecting matplotlib Downloading matplotlib-3.10.6-cp312-cp312-win_amd64.whl.metadata (11 kB) Collecting contourpy>=1.0.1 (from matplotlib) Downloading contourpy-1.3.3-cp312-cp312-win_amd64.whl.metadata (5.5 kB) Collecting cycler>=0.10 (from matplotlib) Downloading cycler-0.12.1-py3-none-any.whl.metadata (3.8 kB) Collecting fonttools>=4.22.0 (from matplotlib) Downloading fonttools-4.59.2-cp312-cp312-win_amd64.whl.metadata (111 kB) Collecting kiwisolver>=1.3.1 (from matplotlib) Downloading kiwisolver-1.4.9-cp312-cp312-win_amd64.whl.metadata (6.4 kB) Collecting numpy>=1.23 (from matplotlib) Downloading numpy-2.3.2-cp312-cp312-win_amd64.whl.metadata (60 kB) Collecting packaging>=20.0 (from matplotlib) Downloading packaging-25.0-py3-none-any.whl.metadata (3.3 kB) Requirement already satisfied: pillow>=8 in c:\users\江江\appdata\local\packages\pythonsoftwarefoundation.python.3.12_qbz5n2kfra8p0\localcache\local-packages\python312\site-packages (from matplotlib) (11.3.0) Collecting pyparsing>=2.3.1 (from matplotlib) Downloading pyparsing-3.2.3-py3-none-any.whl.metadata (5.0 kB) Collecting python-dateutil>=2.7 (from matplotlib) Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl.metadata (8.4 kB) Collecting six>=1.5 (from python-dateutil>=2.7->matplotlib) Downloading six-1.17.0-py2.py3-none-any.whl.metadata (1.7 kB) Downloading matplotlib-3.10.6-cp312-cp312-win_amd64.whl (8.1 MB) ---------------------------------------- 8.1/8.1 MB 10.3 MB/s 0:00:00 Downloading contourpy-1.3.3-cp312-cp312-win_amd64.whl (226 kB) Downloading cycler-0.12.1-py3-none-any.whl (8.3 kB) Downloading fonttools-4.59.2-cp312-cp312-win_amd64.whl (2.3 MB) ---------------------------------------- 2.3/2.3 MB 10.7 MB/s 0:00:00 Downloading kiwisolver-1.4.9-cp312-cp312-win_amd64.whl (73 kB) Downloading numpy-2.3.2-cp312-cp312-win_amd64.whl (12.8 MB) ---------------------------------------- 12.8/12.8 MB 11.5 MB/s 0:00:01 Downloading packaging-25.0-py3-none-any.whl (66 kB) Downloading pyparsing-3.2.3-py3-none-any.whl (111 kB) Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB) Downloading six-1.17.0-py2.py3-none-any.whl (11 kB) Installing collected packages: six, pyparsing, packaging, numpy, kiwisolver, fonttools, cycler, python-dateutil, contourpy, matplotlib ------------ --------------------------- 3/10 [numpy] WARNING: The scripts f2py.exe and numpy-config.exe are installed in 'C:\Users\江江\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. -------------------- ------------------- 5/10 [fonttools] WARNING: The scripts fonttools.exe, pyftmerge.exe, pyftsubset.exe and ttx.exe are installed in 'C:\Users\江江\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed contourpy-1.3.3 cycler-0.12.1 fonttools-4.59.2 kiwisolver-1.4.9 matplotlib-3.10.6 numpy-2.3.2 packaging-25.0 pyparsing-3.2.3 python-dateutil-2.9.0.post0 six-1.17.0 逐句翻译一下
最新发布
09-08
(rtx5070_env) PS E:\PyTorch_Build\pytorch> # 1. 诊断环境问题 (rtx5070_env) PS E:\PyTorch_Build\pytorch> python diagnose.py ============================================================ PyTorch 构建环境诊断 ============================================================ 操作系统: Windows 10 Python版本: 3.10.10 ============================================================ CUDA 验证 ============================================================ [检查] CUDA_HOME环境变量... ✓ 成功: E:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1 [检查] NVCC编译器... Exception in thread Thread-4 (_readerthread): Traceback (most recent call last): File "E:\Python310\lib\threading.py", line 1016, in _bootstrap_inner self.run() File "E:\Python310\lib\threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "E:\Python310\lib\subprocess.py", line 1499, in _readerthread buffer.append(fh.read()) File "E:\Python310\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 13: invalid start byte ❌ 失败 (代码 1): Traceback (most recent call last): File "E:\PyTorch_Build\pytorch\diagnose.py", line 16, in run_check result = subprocess.run( File "E:\Python310\lib\subprocess.py", line 526, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '%CUDA_HOME%\bin\nvcc --version' returned non-zero exit status 1. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\PyTorch_Build\pytorch\diagnose.py", line 78, in <module> main() File "E:\PyTorch_Build\pytorch\diagnose.py", line 45, in main run_check("NVCC编译器", "%CUDA_HOME%\\bin\\nvcc --version", critical=True) File "E:\PyTorch_Build\pytorch\diagnose.py", line 28, in run_check print(e.stderr.strip()) AttributeError: 'NoneType' object has no attribute 'strip' (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 2. 修复环境问题(根据诊断结果) (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 3. 清除虚拟环境(重新开始) (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item -Recurse -Force rtx5070_env -ErrorAction Ignore (rtx5070_env) PS E:\PyTorch_Build\pytorch> python -m venv rtx5070_env (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 4. 激活环境并安装依赖 (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\rtx5070_env\Scripts\Activate.ps1 (rtx5070_env) PS E:\PyTorch_Build\pytorch> pip install -r requirements.txt Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting setuptools<80.0,>=70.1.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/0d/6d/b4752b044bf94cb802d88a888dc7d288baaf77d7910b7dedda74b5ceea0c/setuptools-79.0.1-py3-none-any.whl (1.3 MB) Collecting cmake>=3.27 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/7c/d0/73cae88d8c25973f2465d5a4457264f95617c16ad321824ed4c243734511/cmake-4.1.0-py3-none-win_amd64.whl (37.6 MB) Collecting ninja Using cached https://pypi.tuna.tsinghua.edu.cn/packages/29/45/c0adfbfb0b5895aa18cec400c535b4f7ff3e52536e0403602fc1a23f7de9/ninja-1.13.0-py3-none-win_amd64.whl (309 kB) Collecting numpy Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a3/dd/4b822569d6b96c39d1215dbae0582fd99954dcbcf0c1a13c61783feaca3f/numpy-2.2.6-cp310-cp310-win_amd64.whl (12.9 MB) Collecting packaging Using cached https://pypi.tuna.tsinghua.edu.cn/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl (66 kB) Collecting pyyaml Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b5/84/0fa4b06f6d6c958d207620fc60005e241ecedceee58931bb20138e1e5776/PyYAML-6.0.2-cp310-cp310-win_amd64.whl (161 kB) Collecting requests Using cached https://pypi.tuna.tsinghua.edu.cn/packages/1e/db/4254e3eabe8020b458f1a747140d32277ec7a271daf1d235b70dc0b4e6e3/requests-2.32.5-py3-none-any.whl (64 kB) Collecting six Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl (11 kB) Collecting typing-extensions>=4.10.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl (44 kB) Collecting build[uv] Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cb/8c/2b30c12155ad8de0cf641d76a8b396a16d2c36bc6d50b621a62b7c4567c1/build-1.3.0-py3-none-any.whl (23 kB) Collecting expecttest>=0.3.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/27/fb/deeefea1ea549273817ca7bed3db2f39cc238a75a745a20e3651619f7335/expecttest-0.3.0-py3-none-any.whl (8.2 kB) Collecting filelock Using cached https://pypi.tuna.tsinghua.edu.cn/packages/42/14/42b2651a2f46b022ccd948bca9f2d5af0fd8929c4eec235b8d6d844fbe67/filelock-3.19.1-py3-none-any.whl (15 kB) Collecting fsspec>=0.8.5 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/2f/e0/014d5d9d7a4564cf1c40b5039bc882db69fd881111e03ab3657ac0b218e2/fsspec-2025.7.0-py3-none-any.whl (199 kB) Collecting hypothesis Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cc/82/823c202c8b349ff31a0718e46ff98074bebfb3aa20813091cea07821c25f/hypothesis-6.138.13-py3-none-any.whl (533 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 533.6/533.6 kB ? eta 0:00:00 Collecting jinja2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl (134 kB) Collecting lintrunner Downloading https://pypi.tuna.tsinghua.edu.cn/packages/40/c1/eb0184a324dd25e19b84e52fc44c6262710677737c8acca5d545b3d25ffb/lintrunner-0.12.7-py3-none-win_amd64.whl (1.7 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 27.3 MB/s eta 0:00:00 Collecting networkx>=2.5.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b9/54/dd730b32ea14ea797530a4479b2ed46a6fb250f682a9cfb997e968bf0261/networkx-3.4.2-py3-none-any.whl (1.7 MB) Collecting optree>=0.13.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/74/fa/83d4cd387043483ee23617b048829a1289bf54afe2f6cb98ec7b27133369/optree-0.17.0-cp310-cp310-win_amd64.whl (304 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 304.4/304.4 kB 18.4 MB/s eta 0:00:00 Collecting psutil Downloading https://pypi.tuna.tsinghua.edu.cn/packages/50/1b/6921afe68c74868b4c9fa424dad3be35b095e16687989ebbb50ce4fceb7c/psutil-7.0.0-cp37-abi3-win_amd64.whl (244 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 244.9/244.9 kB 15.6 MB/s eta 0:00:00 Collecting sympy>=1.13.3 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a2/09/77d55d46fd61b4a135c444fc97158ef34a095e5681d0a6c10b75bf356191/sympy-1.14.0-py3-none-any.whl (6.3 MB) Collecting wheel Using cached https://pypi.tuna.tsinghua.edu.cn/packages/0b/2c/87f3254fd8ffd29e4c02732eee68a83a1d3c346ae39bc6822dcbcb697f2b/wheel-0.45.1-py3-none-any.whl (72 kB) Collecting charset_normalizer<4,>=2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e2/c6/f05db471f81af1fa01839d44ae2a8bfeec8d2a8b4590f16c4e7393afd323/charset_normalizer-3.4.3-cp310-cp310-win_amd64.whl (107 kB) Collecting certifi>=2017.4.17 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e5/48/1549795ba7742c948d2ad169c1c8cdbae65bc450d6cd753d124b17c8cd32/certifi-2025.8.3-py3-none-any.whl (161 kB) Collecting idna<4,>=2.5 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl (70 kB) Collecting urllib3<3,>=1.21.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a7/c2/fe1e52489ae3122415c51f387e221dd0773709bad6c6cdaa599e8a2c5185/urllib3-2.5.0-py3-none-any.whl (129 kB) Collecting pyproject_hooks Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bd/24/12818598c362d7f300f18e74db45963dbcb85150324092410c8b49405e42/pyproject_hooks-1.2.0-py3-none-any.whl (10 kB) Collecting colorama Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl (25 kB) Collecting tomli>=1.1.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6e/c2/61d3e0f47e2b74ef40a68b9e6ad5984f6241a942f7cd3bbfbdbd03861ea9/tomli-2.2.1-py3-none-any.whl (14 kB) Collecting uv>=0.1.18 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/45/5e/9bf7004bd53e9279265d73a131fe2a6c7d74c1125c53e805b5e9f4047f37/uv-0.8.14-py3-none-win_amd64.whl (20.7 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 20.7/20.7 MB 50.4 MB/s eta 0:00:00 Collecting attrs>=22.2.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/77/06/bb80f5f86020c4551da315d78b3ab75e8228f89f0162f2c3a819e407941a/attrs-25.3.0-py3-none-any.whl (63 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 63.8/63.8 kB ? eta 0:00:00 Collecting sortedcontainers<3.0.0,>=2.1.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/32/46/9cb0e58b2deb7f82b84065f37f3bffeb12413f947f9388e4cac22c4621ce/sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB) Collecting exceptiongroup>=1.0.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/36/f4/c6e662dade71f56cd2f3735141b265c3c79293c109549c1e6933b0651ffc/exceptiongroup-1.3.0-py3-none-any.whl (16 kB) Collecting MarkupSafe>=2.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/44/06/e7175d06dd6e9172d4a69a72592cb3f7a996a9c396eee29082826449bbc3/MarkupSafe-3.0.2-cp310-cp310-win_amd64.whl (15 kB) Collecting mpmath<1.4,>=1.1.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/43/e3/7d92a15f894aa0c9c4b49b8ee9ac9850d6e63b03c9c32c0367a13ae62209/mpmath-1.3.0-py3-none-any.whl (536 kB) Installing collected packages: sortedcontainers, mpmath, wheel, uv, urllib3, typing-extensions, tomli, sympy, six, setuptools, pyyaml, pyproject_hooks, psutil, packaging, numpy, ninja, networkx, MarkupSafe, lintrunner, idna, fsspec, filelock, expecttest, colorama, cmake, charset_normalizer, certifi, attrs, requests, optree, jinja2, exceptiongroup, build, hypothesis Attempting uninstall: setuptools Found existing installation: setuptools 65.5.0 Uninstalling setuptools-65.5.0: Successfully uninstalled setuptools-65.5.0 Successfully installed MarkupSafe-3.0.2 attrs-25.3.0 build-1.3.0 certifi-2025.8.3 charset_normalizer-3.4.3 cmake-4.1.0 colorama-0.4.6 exceptiongroup-1.3.0 expecttest-0.3.0 filelock-3.19.1 fsspec-2025.7.0 hypothesis-6.138.13 idna-3.10 jinja2-3.1.6 lintrunner-0.12.7 mpmath-1.3.0 networkx-3.4.2 ninja-1.13.0 numpy-2.2.6 optree-0.17.0 packaging-25.0 psutil-7.0.0 pyproject_hooks-1.2.0 pyyaml-6.0.2 requests-2.32.5 setuptools-79.0.1 six-1.17.0 sortedcontainers-2.4.0 sympy-1.14.0 tomli-2.2.1 typing-extensions-4.15.0 urllib3-2.5.0 uv-0.8.14 wheel-0.45.1 [notice] A new release of pip available: 22.3.1 -> 25.2 [notice] To update, run: python.exe -m pip install --upgrade pip (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 5. 运行修复后的构建脚本 (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\build_fixed.ps1 -Verbose # 使用-Verbose获取详细输出 ParserError: E:\PyTorch_Build\pytorch\build_fixed.ps1:19 Line | 19 | & $Command 2>&1 | Tee-Object -FilePath $LogFil … | ~ | Unexpected token '2' in expression or statement. (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 6. 验证安装 (rtx5070_env) PS E:\PyTorch_Build\pytorch> python verify_pytorch.py ================================================== PyTorch 安装验证 ================================================== 操作系统: Windows 10 Traceback (most recent call last): File "E:\PyTorch_Build\pytorch\verify_pytorch.py", line 8, in <module> print(f"PyTorch版本: {torch.__version__}") AttributeError: module 'torch' has no attribute '__version__' (rtx5070_env) PS E:\PyTorch_Build\pytorch> python verify_pytorch_fixed.py Traceback (most recent call last): File "E:\PyTorch_Build\pytorch\verify_pytorch_fixed.py", line 2, in <module> import torch.nn as nn ModuleNotFoundError: No module named 'torch.nn' (rtx5070_env) PS E:\PyTorch_Build\pytorch>
09-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值