Traceback (most recent call last): File "D:\USER\Anaconda3\envs\pytorch_gpu\Lib\site-packages\torch\__init__.py", line 22, in <module> from ._utils import _import_dotted_name, classproperty ImportError: attempted relative import with no known parent
时间: 2023-07-21 22:08:44 浏览: 290
看起来像是你在尝试从 `torch` 模块的 `_utils` 子模块中导入 `_import_dotted_name` 和 `classproperty`,但 Python 解释器无法找到相应的父级模块。这通常是因为你使用了相对路径导入,但你的 Python 脚本不在正确的包结构中。你可以尝试在你的脚本的开头添加以下代码,将当前路径添加到 Python 模块搜索路径中:
```python
import sys
sys.path.append('.')
```
或者你可以查看你的包结构是否正确,并确保你的 Python 脚本位于正确的位置。
相关问题
ERROR: Exception: Traceback (most recent call last): File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcher yield File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_vendor\urllib3\response.py", line 561, in read data = self._fp_read(amt) if not fp_closed else b"" File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_vendor\urllib3\response.py", line 527, in _fp_read return self._fp.read(amt) if amt is not None else self._fp.read() File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 90, in read data = self.__fp.read(amt) File "E:\Anaconda\envs\pytorch\lib\http\client.py", line 463, in read n = self.readinto(b) File "E:\Anaconda\envs\pytorch\lib\http\client.py", line 507, in readinto n = self.fp.readinto(b) File "E:\Anaconda\envs\pytorch\lib\socket.py", line 704, in readinto return self._sock.recv_into(b) File "E:\Anaconda\envs\pytorch\lib\ssl.py", line 1242, in recv_into return self.read(nbytes, buffer) File "E:\Anaconda\envs\pytorch\lib\ssl.py", line 1100, in read return self._sslobj.read(len, buffer) socket.timeout: The read operation timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_internal\cli\base_command.py", line 160, in exc_logging_wrapper status = run_func(*args) File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_internal\cli\req_command.py", line 247, in wrapper return func(self, options, args) File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_internal\commands\install.py", line 419, in run requirement_set = resolver.resolve( File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 92, in resolve result = self._result = resolver.resolve( File "E:\Anaconda\envs\pytorch\lib\site-packages\pip\_vendor\resolvelib\resolvers.py"
看起来你在使用pip下载PyTorch时遇到了一个网络连接超时的错误。这通常是由于网络问题引起的。你可以尝试以下几种方法来解决这个问题:
1. 检查你的网络连接是否正常,确保你能够访问互联网。
2. 重试下载命令,有时候下载命令可能会因为网络问题而失败。你可以再次运行下载命令,看看问题是否得到解决。
3. 更换下载源,有时候下载源的问题也可能导致下载失败。你可以尝试切换到其他镜像源,比如清华大学的镜像源。
```
pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple
```
如果你需要下载支持CUDA的PyTorch版本,可以使用以下命令:
```
pip install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple
```
4. 如果以上方法都不起作用,你可以尝试等待一段时间,然后再次尝试下载命令。可能只是暂时的网络问题。
希望这些方法能够帮助解决你的问题!
Traceback (most recent call last): File "C:\Users\夏芷琳\Desktop\recommendation_model-master\DCN\dcn.py", line 200, in <module> model = DCN(feat_sizes, embedding_size, linear_feature_columns, dnn_feature_columns).to(device) File "D:\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1145, in to return self._apply(convert) File "D:\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 797, in _apply module._apply(fn) File "D:\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 797, in _apply module._apply(fn) File "D:\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 820, in _apply param_applied = fn(param) File "D:\Anaconda\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1143, in convert return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking) File "D:\Anaconda\envs\pytorch\lib\site-packages\torch\cuda\__init__.py", line 239, in _lazy_init raise AssertionError("Torch not compiled with CUDA enabled") AssertionError: Torch not compiled with CUDA enabled
这是一个Python程序出现的错误,错误信息是 Torch not compiled with CUDA enabled。这个错误通常是因为你使用的PyTorch版本没有启用CUDA或CUDA安装出现问题。你可以检查你的PyTorch版本是否支持CUDA,或者重新安装PyTorch并确保安装了CUDA。
阅读全文