MetaGPT
MetaGPT copied to clipboard
[Errno 21] Is a directory: '/app/metagpt/config/key.yaml'
你好,这是我运行Demo时遇到的错误,请帮忙,感谢:
PS C:\Users\23921> docker run --rm `
--privileged
-v /opt/metagpt/config/key.yaml:/app/metagpt/config/key.yaml
-v /opt/metagpt/workspace:/app/metagpt/workspacemetagpt/metagpt:v0.3.1
python startup.py "Write a cli snake game" Traceback (most recent call last): File "/app/metagpt/startup.py", line 7, infrom metagpt.roles import Architect, Engineer, ProductManager, ProjectManager File "/app/metagpt/metagpt/roles/init.py", line 9, in from metagpt.roles.role import Role File "/app/metagpt/metagpt/roles/role.py", line 15, in from metagpt.config import CONFIG File "/app/metagpt/metagpt/config.py", line 114, in CONFIG = Config() File "/app/metagpt/metagpt/utils/singleton.py", line 21, in call cls._instances[cls] = super(Singleton, cls).call(*args, **kwargs) File "/app/metagpt/metagpt/config.py", line 43, in init self._init_with_config_files_and_env(self._configs, yaml_file) File "/app/metagpt/metagpt/config.py", line 96, in _init_with_config_files_and_env with open(_yaml_file, "r", encoding="utf-8") as file: IsADirectoryError: [Errno 21] Is a directory: '/app/metagpt/config/key.yaml'
Same issue with open(_yaml_file, "r", encoding="utf-8") as file: IsADirectoryError: [Errno 21] Is a directory: '/app/metagpt/config/key.yaml'
Issue: IsADirectoryError: [Errno 21] Is a directory: '/app/metagpt/config/key.yaml'
Environment:
- Using Docker Desktop
Symptom:
Encountered an IsADirectoryError
indicating that key.yaml
is being treated as a directory, rather than a file.
Diagnosis:
Upon investigation in Docker Desktop's file explorer, it appears that key.yaml
is indeed being mounted as a directory rather than a YAML file.
Solution:
-
Navigate to the
config.py
File: Go to theapp/metagpt/metagpt
directory and openconfig.py
. -
Add Your API Key: Before making any changes, ensure that your API key is properly entered into
config.yaml
. -
Edit the Reference: Find the string
"key.yaml"
inconfig.py
and replace it with"config.yaml"
.
After performing these steps, the issue was resolved and the application worked as expected.
Explanation:
It seems that Docker Desktop may be mounting key.yaml
as a directory. The above fix redirects the application to look for config.yaml
instead, where the API key is now stored.
Note:
Make sure your API key is securely stored in config.yaml
before making these changes.
Hope this helps anyone encountering the same issue!
Please create /app/metagpt/config/key.yaml
first.
docker run --rm metagpt/metagpt:v0.3.1 cat /app/metagpt/config/config.yaml > /opt/metagpt/config/key.yaml
The above command results in "permission denied". Any clue?
Problem
Windows may encounter the following issues:
- "IsADirectoryError: [Errno 21] Is a directory: '/app/metagpt/config/key.yaml'"
- permission denied
Solution
For Windows, you need to replace "/opt/metagpt" with a directory that Docker has permission to create, such as "D:\Users\x\demo"