Pycharm does not see files in relative path with ../(Pycharm 看不到带有 ../的相对路径中的文件)
问题描述
我正在使用 pycharm 开发一个 python 项目.但是,问题是它拒绝加载相对路径包含 ../
的文件.当我尝试
I am developing a python project using pycharm. However, the problem is that it refuses to load files in which the relative path includes ../
. When I try
self.image = pygame.image.load("../resources/img/prey.png").convert_alpha()
我明白了:
self.image = pygame.image.load("../resources/img/prey.png").convert_alpha()
pygame.error: Couldn't open ../resources/img/prey.png
问题是当我从终端运行我的代码时,它工作正常,这意味着问题出在 pycharm 上.
The thing is that when running my code from the terminal, it works fine, meaning that the problem is with pycharm.
现在的问题是,虽然这最初听起来像许多其他问题,其中目录不是工作目录的一部分,但添加:
Now, the problem is that while this originally sounds like many of the other questions in which the directory is not part of the working directory,adding:
import os
print os.getcwd()
来自 pycharm 给了我 /media/Storage/System 和 dev/Code/Cross Platform/python/boids/current
from pycharm gives me /media/Storage/System and dev/Code/Cross Platform/python/boids/current
我的目录结构似乎是正确的:
which seems correct with my directory structure being:
./current
./resources
./img
prey.png
./objects
modules_that_I_import.py
./experiments
code_that_I_actually_run.py
运行 self.image=pygame.image.load("../resources/img/prey.png").convert_alpha()
的代码在 ./objects代码>
我在带有 Python 2.7
的 Linux Mint 上使用 Pycharm Community Edition 2016.1.2
.
I am using Pycharm Community Edition 2016.1.2
on Linux Mint with Python 2.7
.
感谢任何帮助.
编辑
从命令行运行 os.getcwd
时,我得到 /media/Storage/System 和 dev/Code/Cross Platform/python/boids/current/experiments
when running os.getcwd
from the command line I get /media/Storage/System and dev/Code/Cross Platform/python/boids/current/experiments
推荐答案
转到 Run - Edit Configurations
,选择您的配置
并将 Working directory
更改为 /media/Storage/System 和 dev/Code/Cross Platform/python/boids/current/experiments
.
这篇关于Pycharm 看不到带有 ../的相对路径中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Pycharm 看不到带有 ../的相对路径中的文件


基础教程推荐
- 筛选NumPy数组 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01