実現したいこと
ここに実現したいことを箇条書きで書いてください。
- フォルダ(またはファイル)が読み取り専用になる
前提
Pythonでpipの再現をしています。
パッケージをインストールする機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
shell
1PS C:\Users\hm74c\OneDrive\ドキュメント\pythonライブラリ\_sakurapkg\_sakurapkg\core> sakura debug pip 2● pip 3https://pypi.org 4pip 5 6[Errno 13] Permission denied: './sakurapkg_dependencies/dist/pip'```
上以外の出力はありません。
該当のソースコード
python
1import importlib.util 2import shutil 3import os 4import glob 5import site 6import platform 7import httpx 8import urllib.request 9from bs4 import BeautifulSoup 10from lxml import html 11import json 12import re 13import zipfile 14import sys 15import stat 16 17 def get(self, package, url="https://pypi.org", verison=None): 18 print(url) 19 print(package) 20 if not os.path.exists("./sakurapkg_dependencies/dist/wheel/"): 21 os.makedirs("./sakurapkg_dependencies/dist/wheel/") 22 with httpx.Client() as client: 23 response = client.get(f"{url}/simple/{package}/") 24 if response.status_code == 200: 25 soup = BeautifulSoup(response.text, "lxml") 26 tree = html.fromstring(response.content) 27 whl_links = tree.xpath('//a[contains(@href, "whl")]/@href') 28 latest_whl_link = max(whl_links, key=lambda link: link.split("/")[-1]) 29 urllib.request.urlretrieve(latest_whl_link, f"./sakurapkg_dependencies/dist/wheel/{package}.whl") 30 source_dir = f"./sakurapkg_dependencies/source/{package}" 31 build_dir = "./sakurapkg_dependencies/dist/wheel" 32 kwargs = { 33 "outdir": build_dir, 34 "sdist": True, 35 "wheel": True 36 } 37 if platform.system() == "Windows": 38 site_path = site.getsitepackages()[1] 39 else: 40 site_path = site.getsitepackages()[0] 41 whl_files = glob.glob(f"{build_dir}/*.whl") 42 whl_path = f'./sakurapkg_dependencies/dist/wheel/{package}.whl' 43 if not os.path.exists(f"./sakurapkg_dependencies/dist/{package}"): 44 os.makedirs(f"./sakurapkg_dependencies/dist/{package}") 45 for root, dirs, files in os.walk(f"./sakurapkg_dependencies/"): 46 for file_name in files: 47 full_path = os.path.join(root, file_name) 48 if not os.access(full_path, os.W_OK): 49 os.chmod(full_path, stat.S_IWRITE) 50 with zipfile.ZipFile(whl_path, 'r') as zf: 51 zf.extractall(f"./sakurapkg_dependencies/dist/{package}") 52 for root, dirs, files in os.walk(f"./sakurapkg_dependencies/"): 53 for file_name in files: 54 full_path = os.path.join(root, file_name) 55 if not os.access(full_path, os.W_OK): 56 os.chmod(full_path, stat.S_IWRITE) 57 #shutil.unpack_archive(f"./sakurapkg_dependencies/dist/wheel/{name}.whl", f"./sakurapkg_dependencies/dist/{name}" 58 meta = metadata.load(path=f"./sakurapkg_dependencies/dist/{package}") 59 sys.stdout.write(f"\r{Color.GREEN}●{Color.RESET} {package}") 60 sys.stdout.flush() 61 #os.removedirs(f"./sakurapkg_dependencies/dist/{name}") 62 return meta
##呼び出し元
python
1import toml 2from toml.decoder import TomlDecodeError 3from cleo.commands.command import Command 4from cleo.helpers import argument, option 5import logging, os, requests, sys, subprocess, re, platform 6import itertools 7import threading 8import time 9import sakurapkg 10from sakurapkg.exceptions import sakurapkg_error 11import build 12from pathlib import Path 13import site 14import zipfile 15import sys 16 17logger = logging.getLogger(__name__) 18logging.basicConfig() 19 20class Color: 21 BLACK = '\033[30m'#(文字)黒 22 RED = '\033[31m'#(文字)赤 23 GREEN = '\033[32m'#(文字)緑 24 YELLOW = '\033[33m'#(文字)黄 25 BLUE = '\033[34m'#(文字)青 26 MAGENTA = '\033[35m'#(文字)マゼンタ 27 CYAN = '\033[36m'#(文字)シアン 28 WHITE = '\033[37m'#(文字)白 29 COLOR_DEFAULT = '\033[39m'#文字色をデフォルトに戻す 30 BOLD = '\033[1m'#太字 31 UNDERLINE = '\033[4m'#下線 32 INVISIBLE = '\033[08m'#不可視 33 REVERCE = '\033[07m'#文字色と背景色を反転 34 BG_BLACK = '\033[40m'#(背景)黒 35 BG_RED = '\033[41m'#(背景)赤 36 BG_GREEN = '\033[42m'#(背景)緑 37 BG_YELLOW = '\033[43m'#(背景)黄 38 BG_BLUE = '\033[44m'#(背景)青 39 BG_MAGENTA = '\033[45m'#(背景)マゼンタ 40 BG_CYAN = '\033[46m'#(背景)シアン 41 BG_WHITE = '\033[47m'#(背景)白 42 BG_DEFAULT = '\033[49m'#背景色をデフォルトに戻す 43 RESET = '\033[0m'#全てリセット 44 45class debugger(Command): 46 name = "debug" 47 description = "sakurapkg debugger" 48 arguments = [ 49 argument( 50 "package" 51 ) 52 ] 53 54 def handle(self): 55 package = self.argument("package") 56 #commands = self.argument("cmd") 57 sys.stdout.write(f"\r{Color.BLUE}●{Color.RESET} {package}") 58 sys.stdout.flush() 59 print() 60 from _sakurapkg.core import install_pkg 61 Installer = install_pkg.Installer() 62 meta = Installer.get(package=package, url="https://pypi.org") 63 sys.stdout.write(f"\r{Color.GREEN}●{Color.RESET} {package}") 64 sys.stdout.flush() 65 if len(meta) > 0: 66 for i in range(len(meta)): 67 Installer.get_requires(package=meta[i], url="https://pypi.org") 68 else: 69 return 70 #if commands == "install": 71 # installer = install_pkg.Installer 72 # installer.get(name=package) 73
試したこと
- 管理者権限で実行
- 直前にos.chmodで権限変更(ソースコードにあります)
補足情報(FW/ツールのバージョンなど)
Python3.10.8
Windows11
あなたの回答
tips
プレビュー