如何在google colab上安装python3.8和tensorflow-gpu==2.4

如何解决如何在google colab上安装python3.8和tensorflow-gpu==2.4

以下是我遵循的步骤,但我无法使 tensorflow 正常工作...................................... ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ……

安装python3.8

!sudo add-apt-repository ppa:deadsnakes/ppa
!sudo apt-get update
!sudo apt-get install python3.8
!sudo apt install python3.8-distutils
!sudo apt install python3.8-venv python3.8-dev
!sudo apt-get install python3-pip
!python3.8 -m pip install -U pip setuptools

安装 tensorflow

!python3.8 -m pip install tensorflow tensorflow-gpu
!python3.8 -c 'import tensorflow'

输出:

2021-01-05 03:06:33.030994: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/lib64-nvidia
2021-01-05 03:06:33.031039: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

使用 tensorflow docs

安装 cuda 11
!sudo apt-get update -y
!sudo apt-get install -y libcupti-dev
!export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64
!sudo apt-get install nvidia-kernel-common-455 libnvidia-gl-455 libnvidia-fbc1-455\
 libnvidia-ifr1-455 libnvidia-cfg1-455 xserver-xorg-video-nvidia-455\
  libnvidia-encode-455 nvidia-utils-455 nvidia-dkms-455 libnvidia-decode-455\
   nvidia-compute-utils-455 nvidia-kernel-source-455 libnvidia-extra-455\
    libnvidia-compute-455 nvidia-driver-455
# Add NVIDIA package repositories
!wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
!sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
!sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
!sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
!sudo apt-get update

!wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb

!sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
!sudo apt-get update

# Install NVIDIA driver
!sudo apt-get install --no-install-recommends nvidia-driver-455
# Reboot. Check that GPUs are visible using the command: nvidia-smi

!wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libnvinfer7_7.1.3-1+cuda11.0_amd64.deb
!sudo apt install ./libnvinfer7_7.1.3-1+cuda11.0_amd64.deb
!sudo apt-get update

# Install development and runtime libraries (~4GB)
!sudo apt-get install --no-install-recommends \
    cuda-11-0 \
    libcudnn8=8.0.4.30-1+cuda11.0  \
    libcudnn8-dev=8.0.4.30-1+cuda11.0


# Install TensorRT. Requires that libcudnn8 is installed above.
!sudo apt-get install -y --no-install-recommends libnvinfer7=7.1.3-1+cuda11.0 \
    libnvinfer-dev=7.1.3-1+cuda11.0 \
    libnvinfer-plugin7=7.1.3-1+cuda11.0

然后,当我使用 dqn.py 运行使用 tensorflow 的脚本 !python3.8 dqn.py 时出现此错误

or/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-01-05 20:58:19.951459: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices,tf_xla_enable_xla_devices not set
2021-01-05 20:58:19.952528: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2021-01-05 20:58:19.986076: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1),but there must be at least one NUMA node,so returning NUMA node zero
2021-01-05 20:58:19.986638: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: 
pciBusID: 0000:00:04.0 name: Tesla T4 computeCapability: 7.5
coreClock: 1.59GHz coreCount: 40 deviceMemorySize: 14.73GiB deviceMemoryBandwidth: 298.08GiB/s
2021-01-05 20:58:19.986691: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-01-05 20:58:20.006886: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-01-05 20:58:20.006998: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-01-05 20:58:20.014581: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-01-05 20:58:20.019778: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-01-05 20:58:20.031744: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2021-01-05 20:58:20.035045: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-01-05 20:58:20.038185: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-01-05 20:58:20.038305: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1),so returning NUMA node zero
2021-01-05 20:58:20.038885: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1),so returning NUMA node zero
2021-01-05 20:58:20.039409: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-01-05 20:58:20.039914: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices,tf_xla_enable_xla_devices not set
2021-01-05 20:58:20.040041: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1),so returning NUMA node zero
2021-01-05 20:58:20.040578: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: 
pciBusID: 0000:00:04.0 name: Tesla T4 computeCapability: 7.5
coreClock: 1.59GHz coreCount: 40 deviceMemorySize: 14.73GiB deviceMemoryBandwidth: 298.08GiB/s
2021-01-05 20:58:20.040616: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-01-05 20:58:20.040653: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-01-05 20:58:20.040677: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-01-05 20:58:20.040698: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-01-05 20:58:20.040720: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-01-05 20:58:20.040740: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2021-01-05 20:58:20.040759: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-01-05 20:58:20.040779: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-01-05 20:58:20.040840: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1),so returning NUMA node zero
2021-01-05 20:58:20.041448: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1),so returning NUMA node zero
2021-01-05 20:58:20.041944: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-01-05 20:58:20.041994: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
Traceback (most recent call last):
  File "dqn.py",line 337,in <module>
    mod1 = dqn_conv(en.observation_space.shape,en.action_space.n)
  File "/content/models.py",line 19,in dqn_conv
    x = Conv2D(32,8,4,activation='relu')(x0)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py",line 951,in __call__
    return self._functional_construction_call(inputs,args,kwargs,File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py",line 1090,in _functional_construction_call
    outputs = self._keras_tensor_symbolic_call(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py",line 822,in _keras_tensor_symbolic_call
    return self._infer_output_signature(inputs,input_masks)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py",line 862,in _infer_output_signature
    self._maybe_build(inputs)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py",line 2710,in _maybe_build
    self.build(input_shapes)  # pylint:disable=not-callable
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/layers/convolutional.py",line 198,in build
    self.kernel = self.add_weight(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer.py",line 623,in add_weight
    variable = self._add_variable_with_custom_getter(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/training/tracking/base.py",line 805,in _add_variable_with_custom_getter
    new_variable = getter(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/engine/base_layer_utils.py",line 130,in make_variable
    return tf_variables.VariableV1(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/variables.py",line 260,in __call__
    return cls._variable_v1_call(*args,**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/variables.py",line 206,in _variable_v1_call
    return previous_getter(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/variables.py",line 199,in <lambda>
    previous_getter = lambda **kwargs: default_variable_creator(None,**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/variable_scope.py",line 2604,in default_variable_creator
    return resource_variable_ops.ResourceVariable(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/variables.py",line 264,in __call__
    return super(VariableMetaclass,cls).__call__(*args,**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/resource_variable_ops.py",line 1574,in __init__
    self._init_from_args(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/resource_variable_ops.py",line 1712,in _init_from_args
    initial_value = initial_value()
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/keras/initializers/initializers_v2.py",line 409,in __call__
    return super(VarianceScaling,self).__call__(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/init_ops_v2.py",line 600,in __call__
    return self._random_generator.random_uniform(shape,-limit,limit,dtype)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/init_ops_v2.py",line 1081,in random_uniform
    return op(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/util/dispatch.py",line 201,in wrapper
    return target(*args,**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/random_ops.py",line 289,in random_uniform
    shape = tensor_util.shape_tensor(shape)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/tensor_util.py",line 1035,in shape_tensor
    return ops.convert_to_tensor(shape,dtype=dtype,name="shape")
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/profiler/trace.py",line 163,in wrapped
    return func(*args,**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/ops.py",line 1540,in convert_to_tensor
    ret = conversion_func(value,name=name,as_ref=as_ref)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/constant_op.py",line 339,in _constant_tensor_conversion_function
    return constant(v,name=name)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/constant_op.py",in constant
    return _constant_impl(value,dtype,shape,name,verify_shape=False,File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/constant_op.py",line 276,in _constant_impl
    return _constant_eager_impl(ctx,value,verify_shape)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/constant_op.py",line 301,in _constant_eager_impl
    t = convert_to_eager_tensor(value,ctx,dtype)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/constant_op.py",line 97,in convert_to_eager_tensor
    ctx.ensure_initialized()
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/context.py",line 526,in ensure_initialized
    context_handle = pywrap_tfe.TFE_NewContext(opts)
tensorflow.python.framework.errors_impl.InternalError: cudaGetDevice() failed. Status: CUDA driver version is insufficient for CUDA runtime version

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res