问题遇到的现象和发生背景
在学深度强化学习框架Acme,其中的教学quickstart是在jupyter中运行。
我把acme安在了虚拟环境中
简要环境配置:
python3.9
jupyter-console6.4.3
dm-acme0.4.0
问题相关代码,请勿粘贴截图
问题相关代码:
import IPython
from acme import environment_loop
from acme import specs
from acme import wrappers
from acme.agents.tf import d4pg
from acme.tf import networks
from acme.tf import utils as tf2_utils
from acme.utils import loggers
import numpy as np
import sonnet as snt
# Import the selected environment lib
if environment_library == 'dm_control':
from dm_control import suite
elif environment_library == 'gym':
import gym
# Imports required for visualization
import pyvirtualdisplay
import imageio
import base64
# Set up a virtual display for rendering.
display = pyvirtualdisplay.Display(visible=0, size=(1400, 900)).start()
运行结果及报错内容
报错内容:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Input In [1], in <cell line: 3>()
1 import IPython
----> 3 from acme import environment_loop
4 from acme import specs
5 from acme import wrappers
File ~/anaconda3/envs/acme/lib/python3.9/site-packages/acme/__init__.py:35, in <module>
32 from acme.core import Worker
34 # Expose the environment loop.
---> 35 from acme.environment_loop import EnvironmentLoop
37 from acme.specs import make_environment_spec
File ~/anaconda3/envs/acme/lib/python3.9/site-packages/acme/environment_loop.py:26, in <module>
24 from acme.utils import loggers
25 from acme.utils import observers as observers_lib
---> 26 from acme.utils import signals
28 import dm_env
29 from dm_env import specs
File ~/anaconda3/envs/acme/lib/python3.9/site-packages/acme/utils/signals.py:22, in <module>
19 import threading
20 from typing import Any, Callable, Optional
---> 22 import launchpad
24 _Handler = Callable[[], Any]
27 @contextlib.contextmanager
28 def runtime_terminator(callback: Optional[_Handler] = None):
File ~/anaconda3/envs/acme/lib/python3.9/site-packages/launchpad/__init__.py:36, in <module>
33 from launchpad.launch.launch import launch
35 # Nodes
---> 36 from launchpad.nodes.courier.node import CourierHandle
37 from launchpad.nodes.courier.node import CourierNode
38 from launchpad.nodes.courier.node import CourierClient
File ~/anaconda3/envs/acme/lib/python3.9/site-packages/launchpad/nodes/courier/node.py:21, in <module>
18 from typing import Callable, Generic, TypeVar
20 from absl import logging
---> 21 import courier
22 from launchpad import address as lp_address
23 from launchpad.launch import worker_manager
File ~/anaconda3/envs/acme/lib/python3.9/site-packages/courier/__init__.py:26, in <module>
11 # Copyright 2020 DeepMind Technologies Limited. All rights reserved.
12 #
13 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
22 # See the License for the specific language governing permissions and
23 # limitations under the License.
25 """Courier module."""
---> 26 from courier.python.client import Client # pytype: disable=import-error
27 from courier.python.client import list_methods # pytype: disable=import-error
28 from courier.python.py_server import Server
File ~/anaconda3/envs/acme/lib/python3.9/site-packages/courier/python/client.py:30, in <module>
27 import datetime
28 from typing import List, Optional, Union
---> 30 from courier.python import py_client
31 # Numpy import needed for proper operation of ../serialization/py_serialize.cc
32 import numpy
ImportError: libpython3.9.so.1.0: cannot open shared object file: No such file or directory
我的解答思路和尝试过的方法
错误信息最后几行是在
~/anaconda3/envs/acme/lib/python3.9/site-packages/courier/python
这个目录下,我去看一看
发现最后导入不成功的py_client是动态链接库.so文件
根据这个
(网址有3个连续的f,没法贴上来。)
我检查了python路径,发现相关目录没在路径中,然后就把
~/anaconda3/envs/acme/lib/python3.9/site-packages/courier/python
添加到路径中
(acme) jw@Z8:~$ python
Python 3.9.0 (default, Nov 15 2020, 14:28:56)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/jw/anaconda3/envs/acme/lib/python39.zip',
'/home/jw/anaconda3/envs/acme/lib/python3.9',
'/home/jw/anaconda3/envs/acme/lib/python3.9/lib-dynload',
'/home/jw/anaconda3/envs/acme/lib/python3.9/site-packages']
>>> sys.path.append('/home/jw/anaconda3/envs/acme/lib/python3.9/site-packages/courier/python')
>>> sys.path
['', '/home/jw/anaconda3/envs/acme/lib/python39.zip',
'/home/jw/anaconda3/envs/acme/lib/python3.9',
'/home/jw/anaconda3/envs/acme/lib/python3.9/lib-dynload',
'/home/jw/anaconda3/envs/acme/lib/python3.9/site-packages',
'/home/jw/anaconda3/envs/acme/lib/python3.9/site-packages/courier/python']
但是还是报错,而且退出python然后再次查看发现我自己添加的路径消失了。
我想要达到的结果
请大家告诉我怎么才能导入这个py_client.so
谢谢您的回答。