[python deep learning] solve the problems encountered

Table of contents

一、RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb

二、AttributeError: module ‘tensorflow’ has no attribute ‘flags’

3. Please update conda by running

四、to search for alternate channels that may provide the conda package you're looking for, navigate to

五、RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False


一、RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb

Problem: Import  torch reports an error: RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb

Reason: This is a problem that the numpy version does not match the python version

solve:

  1. Uninstall the original version of numpy
  2. Download the matching numpy version Find the corresponding version of numpy
    at https://www.lfd.uci.edu/~gohlke/pythonlibs/ , and download it locally
  3. Install

 

二、AttributeError: module ‘tensorflow’ has no attribute ‘flags’

Problem: In my code, the error is caused by the command FLAGS = tf.flags.FLAGS. The main reason is that the tensorflow I downloaded is the latest version 2.1, and I can modify tensorflow to version 1.9.

solve:

(2) The second method is to search for tf.flags in the tensorflow official online documentation. By looking at the figure below, you can see that the flags module has been moved to compat.v1. The original command is changed to FLAGS = tf.compat.v1.flags.FLAGS That's it.

3. Please update conda by running

Problem: When installing the numpy third-party library, I found a prompt after typing: There is the latest conda version to download

conda update -n base -c defaults conda

Then, I ran the command to update conda, but an error was reported: EnvironmentNotWritableError: The current user does not have write permissions to the target environment.

Reason: Conda is installed in the C disk of the virtual machine without permission to write.

Solution: After exiting pycharm, reopen pycharm as an administrator, and enter the command again to update conda.

Found that the update was successful.

四、to search for alternate channels that may provide the conda package you're looking for, navigate to

Problem: When installing a python package (not specifically for a specific package, this happens sometimes for various packages. The current channel will be unavailable and an error will be reported.

Reason: In fact, it is very simple. It tells you that no suitable installation package can be found in the default download channel list of this command. It recommends that you go to the anaconda official website to find a matching installation package and download it yourself.

solve:

(1) You need to go to https://anaconda.org, search for other channels you want to install this package on the search bar above, and show how to find other channels of igraph below.

First enter the above URL, you can see the search bar at the top, search for numpy, all packages with the "numpy" field in the package name will appear:

(2) Then run any command provided on the page under the path corresponding to your command line window or Anaconda Prompt window.

(3)

五、RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False

Error:

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Solution: add map_location='cpu' when loading the model

Guess you like

Origin blog.csdn.net/qq_45956730/article/details/131696672