@VTR

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

古い書籍に載っているコードのライブラリのバージョンの確認方法

質問内容:皆さんはどうやってコードに書かれたライブラリのバージョンを判別していますか?

詳細:私は現在強化学習の勉強をしており、教科書"現場で使える!Python深層強化学習入門 強化学習と深層学習による探索と制御"を読んでおります。
https://www.amazon.co.jp/gp/product/B07SVMGBZN/ref=ppx_yo_dt_b_d_asin_title_351_o03?ie=UTF8&psc=1

この教科書は発行が2019年とそこそこ古いですが、そのためか掲載されているコードで当時と今のバージョンの違いによるエラーがよく発生します。
その際ライブラリ等をこの書籍が発行された当時のバージョンにダウングレードすれば一番早い解決法だと思っているのですが、皆さんはどうやって古いコードに書かれたライブラリのバージョンを判別しているのでしょうか?

例えば以下のコードを実行すると、

import collections
import csv
from datetime import datetime
import os

import gym
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import tensorflow as tf

from agent.policy_estimator import PolicyEstimator
from agent.value_estimator import ValueEstimator

plt.style.use('seaborn-darkgrid') #ここが原因でエラーが発生!

このようなエラーが発生してしまいます。


FileNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.11/dist-packages/matplotlib/style/core.py in use(style)
128 try:
--> 129 style = _rc_params_in_file(style)
130 except OSError as err:

4 frames
/usr/local/lib/python3.11/dist-packages/matplotlib/init.py in _rc_params_in_file(fname, transform, fail_on_error)
902 rc_temp = {}
--> 903 with _open_file_or_url(fname) as fd:
904 try:

/usr/lib/python3.11/contextlib.py in enter(self)
136 try:
--> 137 return next(self.gen)
138 except StopIteration:

/usr/local/lib/python3.11/dist-packages/matplotlib/init.py in _open_file_or_url(fname)
879 fname = os.path.expanduser(fname)
--> 880 with open(fname, encoding='utf-8') as f:
881 yield f

FileNotFoundError: [Errno 2] No such file or directory: 'seaborn-darkgrid'

The above exception was the direct cause of the following exception:

OSError Traceback (most recent call last)
in ()
44 from agent.value_estimator import ValueEstimator
45
---> 46 plt.style.use('seaborn-darkgrid')
47
48

/usr/local/lib/python3.11/dist-packages/matplotlib/style/core.py in use(style)
129 style = _rc_params_in_file(style)
130 except OSError as err:
--> 131 raise OSError(
132 f"{style!r} is not a valid package style, path of style "
133 f"file, URL of style file, or library style name (library "

OSError: 'seaborn-darkgrid' is not a valid package style, path of style file, URL of style file, or library style name (library styles are listed in style.available)

OSError: 'seaborn-darkgrid' is not a valid package style・・・はseabornのバージョンを下げれば解決すると思うのですが、探すのがなかなか大変です💦

0 likes

2Answer

書籍の冒頭で説明されている環境で確認できませんか?

『 Colaboratory 環境 』にあるURLを踏むと、以下の画面が開きます。ここに各ライブラリのバージョンが出ています。

scr.png

2Like

古い書籍に載っているコードのライブラリのバージョンの確認方法

ちゃんとした書籍なら書籍内(前書きの後付近)に実行環境についての記述があるかと思います。
Githubにてコードを公開している場合にはそこに記述があるかもしれません。

どちらも無くて困っているなら出版社、あるいは著者に問い合わせれば良いかと思います。

0Like

Your answer might help someone💌