質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Anaconda

Anacondaは、Python本体とPythonで利用されるライブラリを一括でインストールできるパッケージです。環境構築が容易になるため、Python開発者間ではよく利用されており、商用目的としても利用できます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

2254閲覧

shutil.pyのパーミッションエラーについて

nifill

総合スコア7

Anaconda

Anacondaは、Python本体とPythonで利用されるライブラリを一括でインストールできるパッケージです。環境構築が容易になるため、Python開発者間ではよく利用されており、商用目的としても利用できます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/06/27 04:02

前提・実現したいこと

tensorflow、magenta(楽曲生成ライブリ)を使用し、自動楽曲生成をしたいです。

発生している問題・エラーメッセージ

コマンド実行中に、パーミッションエラーが出てしまっています。
エラーのファイルをみると、shutil.pyというファイルのファイルを読み込み権限したところでパーミッションエラーがでているところまでは理解できました。

ですが、標準ライブラリ?というか共通のファイルだと思うので、shutil.pyでのエラーが考えにくく、
ファイル権限や管理者権限での実行を試しましたが全く分からなく、、
教えていただけませんでしょうか。。

(base) C:\Users\Administrator>performance_rnn_generate ^ More? --config=multiconditioned_performance_with_dynamics ^ More? --bundle_file=C:\Users\Administrator\Documents\AIvirtualmusic\multiconditioned_performance_with_dynamics.mag ^ More? --output_dir=C:\Users\Administrator\Documents\AIvirtualmusic\sample ^ More? --num_outputs=10 ^ More? --num_steps=3000 ^ More? --notes_per_second=4 ^ More? --pitch_class_histogram="[2, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1]" ^ More? --primer_pitches="[71,67,64,60]" 2020-06-27 12:22:37.978807: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll WARNING:tensorflow:From c:\programdata\anaconda3\lib\site-packages\tensorflow\python\compat\v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term 2020-06-27 12:22:41.288246: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll 2020-06-27 12:22:41.367721: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5 coreClock: 1.68GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 312.97GiB/s 2020-06-27 12:22:41.367840: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll 2020-06-27 12:22:41.373905: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll 2020-06-27 12:22:41.377125: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll 2020-06-27 12:22:41.966826: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0: N 2020-06-27 12:22:41.967443: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4729 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2060, pci bus id: 0000:01:00.0, compute capability: 7.5) 2020-06-27 12:22:41.970803: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x21e5b317360 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices: 2020-06-27 12:22:41.970881: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): GeForce RTX 2060, Compute Capability 7.5 INFO:tensorflow:Restoring parameters from C:\Users\ADMINI~1\AppData\Local\Temp\tmpru9djg85\model.ckpt I0627 12:22:42.155020 9804 saver.py:1293] Restoring parameters from C:\Users\ADMINI~1\AppData\Local\Temp\tmpru9djg85\model.ckpt INFO:tensorflow:Need to generate 2949 more steps for this sequence, will try asking for 472 RNN steps I0627 12:22:42.351563 9804 performance_sequence_generator.py:240] Need to generate 2949 more steps for this sequence, will try asking for 472 RNN steps 2020-06-27 12:22:42.372767: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll INFO:tensorflow:Beam search yields sequence with log-likelihood: -1197.357300 I0627 12:22:43.495029 9804 events_rnn_model.py:381] Beam search yields sequence with log-likelihood: -1197.357300 INFO:tensorflow:Need to generate 1120 more steps for this sequence, will try asking for 180 RNN steps I0627 12:22:43.496013 9804 performance_sequence_generator.py:240] Need to generate 1120 more steps for this sequence, will try asking for 180 RNN steps INFO:tensorflow:Beam search yields sequence with log-likelihood: -1571.538330 I0627 12:22:44.054311 9804 events_rnn_model.py:381] Beam search yields sequence with log-likelihood: -1571.538330 INFO:tensorflow:Need to generate 374 more steps for this sequence, will try asking for 60 RNN steps I0627 12:22:44.055281 9804 performance_sequence_generator.py:240] Need to generate 374 more steps for this sequence, will try asking for 60 RNN steps INFO:tensorflow:Beam search yields sequence with log-likelihood: -1679.903442 I0627 12:22:44.501518 9804 events_rnn_model.py:381] Beam search yields sequence with log-likelihood: -1679.903442 INFO:tensorflow:Need to generate 112 more steps for this sequence, will try asking for 18 RNN steps I0627 12:22:44.503512 9804 performance_sequence_generator.py:240] Need to generate 112 more steps for this sequence, will try asking for 18 RNN steps INFO:tensorflow:Beam search yields sequence with log-likelihood: -1715.293213 I0627 12:22:44.970277 9804 events_rnn_model.py:381] Beam search yields sequence with log-likelihood: -1715.293213 INFO:tensorflow:Need to generate 80 more steps for this sequence, will try asking for 13 RNN steps I0627 12:22:44.972363 9804 performance_sequence_generator.py:240] Need to generate 80 more steps for this sequence, will try asking for 13 RNN steps INFO:tensorflow:Beam search yields sequence with log-likelihood: -1747.813232 I0627 12:22:45.388950 9804 events_rnn_model.py:381] Beam search yields sequence with log-likelihood: -1747.813232 Traceback (most recent call last): File "c:\programdata\anaconda3\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\programdata\anaconda3\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\ProgramData\Anaconda3\Scripts\performance_rnn_generate.exe\__main__.py", line 7, in <module> File "c:\programdata\anaconda3\lib\site-packages\magenta\models\performance_rnn\performance_rnn_generate.py", line 290, in console_entry_point tf.app.run(main) File "c:\programdata\anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "c:\programdata\anaconda3\lib\site-packages\absl\app.py", line 299, in run _run_main(main, args) File "c:\programdata\anaconda3\lib\site-packages\absl\app.py", line 250, in _run_main sys.exit(main(argv)) File "c:\programdata\anaconda3\lib\site-packages\magenta\models\performance_rnn\performance_rnn_generate.py", line 285, in main run_with_flags(generator) File "c:\programdata\anaconda3\lib\site-packages\magenta\models\performance_rnn\performance_rnn_generate.py", line 248, in run_with_flags note_seq.sequence_proto_to_midi_file(generated_sequence, midi_path) File "c:\programdata\anaconda3\lib\site-packages\note_seq\midi_io.py", line 373, in sequence_proto_to_midi_file drop_events_n_seconds_after_last_note) File "c:\programdata\anaconda3\lib\site-packages\note_seq\midi_io.py", line 218, in note_sequence_to_midi_file copyfile(temp_file.name, output_file) File "c:\programdata\anaconda3\lib\shutil.py", line 120, in copyfile with open(src, 'rb') as fsrc: PermissionError: [Errno 13] Permission denied: 'C:\Users\ADMINI~1\AppData\Local\Temp\tmpn64j79d8' (base) C:\Users\Administrator>

該当のソースコード

python

1performance_rnn_generate ^ 2--config=multiconditioned_performance_with_dynamics ^ 3--bundle_file=C:\Users\Administrator\Documents\AIvirtualmusic\multiconditioned_performance_with_dynamics.mag ^ 4--output_dir=C:\Users\Administrator\Documents\AIvirtualmusic\sample ^ 5--num_outputs=10 ^ 6--num_steps=3000 ^ 7--notes_per_second=4 ^ 8--pitch_class_histogram="[2, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1]" ^ 9--primer_pitches="[71,67,64,60]"

試したこと

・管理者権限での実行
・ファイル権限の確認
を行いましたが、他サイトでの解決策では私の環境では解決できなかったため、皆様のお力を借りられたらと思っています。。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yymmt

2020/06/27 06:50

2点確認したいです。 空きディスク容量は足りていますか? 再起動しても同じ現象が起こりますか?
nifill

2020/06/27 07:38

はい、空きディスクは300GBほどあります。。 再起動しても同じ現象が起きています。 何卒よろしくお願い致します、、
guest

回答1

0

ベストアンサー

解決はしていませんがwork aroundとして示します。
midi_io.pyにパッチを当ててください。

diff

1--- a/midi_io.py 2+++ b/midi_io.py 3@@ -209,13 +209,15 @@ def note_sequence_to_midi_file(sequence, output_file, 4 """ 5 pretty_midi_object = note_sequence_to_pretty_midi( 6 sequence, drop_events_n_seconds_after_last_note) 7- with tempfile.NamedTemporaryFile() as temp_file: 8+ with tempfile.NamedTemporaryFile(delete=False) as temp_file: 9 pretty_midi_object.write(temp_file) 10 # Before copying the file, flush any contents 11 temp_file.flush() 12 # And back the file position to top (not need for Copy but for certainty) 13 temp_file.seek(0) 14- copyfile(temp_file.name, output_file) 15+ copyfile(temp_file.name, output_file) 16+ import os 17+ os.remove(temp_file.name)

以下、調査結果になります。
エラー発生箇所を再現した短いコードは下記の通りです。

python

1import tempfile 2from shutil import copyfile 3 4output_file = "aaa.txt" 5with tempfile.NamedTemporaryFile() as temp_file: 6 temp_file.write(b"hello") 7 temp_file.flush() 8 temp_file.seek(0) 9 copyfile(temp_file.name, output_file)

私のWindows 10環境では、同様にcopyfileの箇所でPermissionエラーが発生しました。

terminal

1PermissionError: [Errno 13] Permission denied: 'C:\Users\guest\AppData\Local\Temp\tmphtl6tglg'

ここから作成したテンポラリファイルに対するアクセス許可が得られていないことが分かります。試しに

python

1with tempfile.NamedTemporaryFile(delete=False) as temp_file: 2 ...

とすると、エラーなく終了します。

参考URL:

投稿2020/06/27 09:03

編集2020/06/28 07:15
yymmt

総合スコア1615

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nifill

2020/06/27 10:02

ありがとうございます!早速midi_io.pyの該当ファイルを書き換えてみました。 今度はパーミッションエラーにはならず、 ーーー File "c:\programdata\anaconda3\lib\site-packages\note_seq\midi_io.py", line 220, in note_sequence_to_midi_file os.remove(tempfile.name) AttributeError: module 'tempfile' has no attribute 'name' ーーー となりました。同名ファイルだとだめ・・・?的なことかと思いますが、教えていただけませんでしょうか。。
yymmt

2020/06/27 10:04

すいません、typoしました。 tempfile.nameではなくtemp_file.nameです。
nifill

2020/06/27 15:50

ありがとうございます!助かります、、 ただ、「temp_file.name」に変更したところ、 再度パーミッションエラーとなりました。。 ・再起動 ・管理者権限 は確認しています。。 何卒よろしくお願いいたします。。
yymmt

2020/06/28 00:29

copyfileの行のインデントを無くすとどうなりますか? 今のコードだとwithブロックの中にいると思いますが、この中だとまだ開いたままなので。ただテストコードだとそれで正常に動いているので同じ結果になるかも知れませんが・・・。
nifill

2020/06/28 07:03

ありがとうございます!! >copyfileの行のインデントを無くすとどうなりますか? →できました!!本当にありがとうございます。 パーミッションエラーもなし、AttributeErrorもなしです。 助かりました、、これで仕事ができます。。 ありがとうございました!!
yymmt

2020/06/28 07:12

確認ありがとうございます。diffのほうも修正しておきます。謎は深まるばかり・・・。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問