Pip install can't resolve opencv dependency in JetPack4.3

Hi all.

I’m want to install stable_baseline what is python module for deep reinforcement learning. But failed to install using by pip. The cause is pip can not resolve opencv-python as dependency. Basically JetPack4.3 has a opencv-python, but pip can not locate as dependency.

Is there any good way?

Best regards.

1 Like

You can use this script to install OpenCV, however it won’t perform as well as solutions designed speficifcally with Tegra in mind (like DeepStream)

Is this a way to reproduce your problem?

【Problem】
pip3 install stable-baselines

Defaulting to user installation because normal site-packages is not writeable
Collecting stable-baselines
  Downloading stable_baselines-2.10.0-py3-none-any.whl (248 kB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 248 kB 2.1 MB/s 
Collecting pandas
  Downloading pandas-1.0.3.tar.gz (5.0 MB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 5.0 MB 920 kB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: scipy in ./.local/lib/python3.6/site-packages (from stable-baselines) (1.4.1)
Collecting gym[atari,classic_control]>=0.11
  Downloading gym-0.17.1.tar.gz (1.6 MB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1.6 MB 7.0 MB/s 
Requirement already satisfied: matplotlib in ./.local/lib/python3.6/site-packages (from stable-baselines) (3.2.1)
Collecting cloudpickle>=0.5.5
  Downloading cloudpickle-1.3.0-py2.py3-none-any.whl (26 kB)
ERROR: Could not find a version that satisfies the requirement opencv-python (from stable-baselines) (from versions: none)
ERROR: No matching distribution found for opencv-python (from stable-baselines)

If so, the dependency issue that occurs when installing stable-baselines is not a JetPack/OpenCV issue, but a stable-baselines and gym issue.

【Solution】
・Download the source code with git clone. (stable-baselines, gym)
・Edit setup.py to remove the problematic pip dependency settings.

After that, installation is possible.
Please install the required packages separately. (pip3 install pandas, etc.)

・Download the source code with git clone. (stable-baselines, gym)

mkdir ~/github/
cd ~/github
git clone https://github.com/hill-a/stable-baselines
git clone https://github.com/openai/gym

【stable-baselines】
vi ~/github/stable-baselines/setup.py
diff -u stable-baselines/setup.py.org stable-baselines/setup.py

    --- stable-baselines/setup.py.org	2020-04-23 10:34:43.224638685 +0900
    +++ stable-baselines/setup.py	2020-04-23 11:36:31.331999849 +0900
    @@ -117,14 +117,14 @@
               'stable_baselines': ['py.typed'],
           },
           install_requires=[
    -          'gym[atari,classic_control]>=0.11',
    -          'scipy',
    -          'joblib',
    -          'cloudpickle>=0.5.5',
    -          'opencv-python',
    -          'numpy',
    -          'pandas',
    -          'matplotlib'
    +          #'gym[atari,classic_control]>=0.11',
    +          #'scipy',
    +          #'joblib',
    +          #'cloudpickle>=0.5.5',
    +          #'opencv-python',
    +          #'numpy',
    +          #'pandas',
    +          #'matplotlib'
           ] + find_tf_dependency(),
           extras_require={
             'mpi': [

install stable-baselines

cd ~/github/stable-baselines
pip3 install -e .

【gym】
vi ~/github/gym/setup.py
diff -u gym/setup.py.org gym/setup.py

--- gym/setup.py.org	2020-04-23 10:54:09.873214037 +0900
+++ gym/setup.py	2020-04-23 10:55:08.559488149 +0900
@@ -7,7 +7,7 @@
 
 # Environment-specific dependencies.
 extras = {
-  'atari': ['atari_py~=0.2.0', 'Pillow', 'opencv-python'],
+  'atari': ['atari_py~=0.2.0', 'Pillow'],
   'box2d': ['box2d-py~=2.3.5'],
   'classic_control': [],
   'mujoco': ['mujoco_py>=1.50, <2.0', 'imageio'],

install gym

cd ~/github/gym
pip3 install -e .

【test code】

import gym

from stable_baselines.common.policies import MlpPolicy
from stable_baselines.common.vec_env import DummyVecEnv
from stable_baselines import PPO2

env = gym.make('CartPole-v1')
# Optional: PPO2 requires a vectorized environment to run
# the env is now wrapped automatically when passing it to the constructor
# env = DummyVecEnv([lambda: env])

model = PPO2(MlpPolicy, env, verbose=1)
model.learn(total_timesteps=10000)

obs = env.reset()
for i in range(1000):
    action, _states = model.predict(obs)
    obs, rewards, dones, info = env.step(action)
    env.render()

env.close()

I run this code on xavier jetpack 4.3.
It seems to be working.

python a
2020-04-23 11:22:12.228691: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
  * https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.

Wrapping the env in a DummyVecEnv.
WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/common/tf_util.py:191: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/common/tf_util.py:200: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2020-04-23 11:22:21.250862: W tensorflow/core/platform/profile_utils/cpu_utils.cc:98] Failed to find bogomips in /proc/cpuinfo; cannot determine CPU frequency
2020-04-23 11:22:21.251782: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2c2a2940 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-04-23 11:22:21.251875: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-04-23 11:22:21.277550: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-04-23 11:22:21.427793: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:950] ARM64 does not support NUMA - returning NUMA node zero
2020-04-23 11:22:21.428238: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2b6e7bf0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-04-23 11:22:21.428369: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Xavier, Compute Capability 7.2
2020-04-23 11:22:21.428997: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:950] ARM64 does not support NUMA - returning NUMA node zero
2020-04-23 11:22:21.429204: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Xavier major: 7 minor: 2 memoryClockRate(GHz): 1.377
pciBusID: 0000:00:00.0
2020-04-23 11:22:21.429340: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2020-04-23 11:22:21.460582: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2020-04-23 11:22:21.486875: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2020-04-23 11:22:21.523490: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10.0
2020-04-23 11:22:21.561647: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10.0
2020-04-23 11:22:21.584001: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10.0
2020-04-23 11:22:21.654566: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-04-23 11:22:21.655115: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:950] ARM64 does not support NUMA - returning NUMA node zero
2020-04-23 11:22:21.655503: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:950] ARM64 does not support NUMA - returning NUMA node zero
2020-04-23 11:22:21.655590: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0
2020-04-23 11:22:21.655772: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2020-04-23 11:22:24.034253: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-04-23 11:22:24.036868: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186]      0 
2020-04-23 11:22:24.036969: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0:   N 
2020-04-23 11:22:24.038026: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:950] ARM64 does not support NUMA - returning NUMA node zero
2020-04-23 11:22:24.038447: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:950] ARM64 does not support NUMA - returning NUMA node zero
2020-04-23 11:22:24.038640: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 445 MB memory) -> physical GPU (device: 0, name: Xavier, pci bus id: 0000:00:00.0, compute capability: 7.2)
WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/common/policies.py:116: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/common/input.py:25: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/common/policies.py:561: flatten (from tensorflow.python.layers.core) is deprecated and will be removed in a future version.
Instructions for updating:
Use keras.layers.flatten instead.
WARNING:tensorflow:From /home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_core/python/layers/core.py:332: Layer.apply (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version.
Instructions for updating:
Please use `layer.__call__` method instead.
WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/common/tf_layers.py:123: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/common/distributions.py:326: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/common/distributions.py:327: The name tf.log is deprecated. Please use tf.math.log instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/ppo2/ppo2.py:190: The name tf.summary.scalar is deprecated. Please use tf.compat.v1.summary.scalar instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/ppo2/ppo2.py:198: The name tf.trainable_variables is deprecated. Please use tf.compat.v1.trainable_variables instead.

WARNING:tensorflow:From /home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_core/python/ops/math_grad.py:1424: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/ppo2/ppo2.py:206: The name tf.train.AdamOptimizer is deprecated. Please use tf.compat.v1.train.AdamOptimizer instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/ppo2/ppo2.py:240: The name tf.global_variables_initializer is deprecated. Please use tf.compat.v1.global_variables_initializer instead.

WARNING:tensorflow:From /home/ubuntu/github/stable-baselines/stable_baselines/ppo2/ppo2.py:242: The name tf.summary.merge_all is deprecated. Please use tf.compat.v1.summary.merge_all instead.

2020-04-23 11:22:26.160466: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
---------------------------------------
| approxkl           | 6.406616e-05   |
| clipfrac           | 0.0            |
| explained_variance | 0.0302         |
| fps                | 45             |
| n_updates          | 1              |
| policy_entropy     | 0.69308        |
| policy_loss        | -0.00029999367 |
| serial_timesteps   | 128            |
| time_elapsed       | 3.86e-05       |
| total_timesteps    | 128            |
| value_loss         | 40.308636      |
---------------------------------------
--------------------------------------
| approxkl           | 7.6444585e-06 |
| clipfrac           | 0.0           |
| explained_variance | 0.00111       |
| fps                | 120           |
| n_updates          | 2             |
| policy_entropy     | 0.69283825    |
| policy_loss        | -1.502689e-06 |
| serial_timesteps   | 256           |
| time_elapsed       | 2.81          |
| total_timesteps    | 256           |
| value_loss         | 25.517273     |
--------------------------------------
--------------------------------------
| approxkl           | 4.6624176e-05 |
| clipfrac           | 0.0           |
| explained_variance | -0.0088       |
| fps                | 131           |
| n_updates          | 3             |
| policy_entropy     | 0.6926168     |
| policy_loss        | -0.0017333322 |
| serial_timesteps   | 384           |
| time_elapsed       | 3.88          |
| total_timesteps    | 384           |
| value_loss         | 42.726902     |
--------------------------------------
--------------------------------------
| approxkl           | 7.5763994e-05 |
| clipfrac           | 0.0           |
| explained_variance | -0.0303       |
| fps                | 117           |
| n_updates          | 4             |
| policy_entropy     | 0.6916568     |
| policy_loss        | -0.0009098172 |
| serial_timesteps   | 512           |
| time_elapsed       | 4.85          |
| total_timesteps    | 512           |
| value_loss         | 50.852077     |
--------------------------------------

Thank you for your comment.
I already know both solution and ran those. In this topic I want to use pre-install opencv on JetPack for stable baselines install. Because, I whould you make it easy installation own software what depends on stable_baselines.

In addition this topic is problem of pip that pre-installed on JetPack. Because stable_baseline and gym can installed in other platform such as windows, macOS, and other Linux distribution.

Best regards.

1 Like