繁体   English   中英

Pycharm 看不到相对路径中带有 ../ 的文件

[英]Pycharm does not see files in relative path with ../

我正在使用 pycharm 开发一个 python 项目。 但是,问题在于它拒绝加载相对路径包含../ 当我尝试

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 上。

现在,问题是,虽然这最初听起来像目录不属于工作目录的一部分的许多其他问题,但添加:

import os
print os.getcwd()

从 pycharm 给我/media/Storage/System and dev/Code/Cross Platform/python/boids/current

我的目录结构似乎是正确的:

./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

我在 Linux Mint 和Python 2.7上使用Pycharm Community Edition 2016.1.2

任何帮助表示赞赏。

编辑

从命令行运行os.getcwd ,我得到/media/Storage/System and dev/Code/Cross Platform/python/boids/current/experiments

转到Run - Edit Configurations ,选择您的配置

运行配置编辑

并将Working directory更改为/media/Storage/System and dev/Code/Cross Platform/python/boids/current/experiments

工作目录编辑

当我将 python 文件移动到另一个目录时,我遇到了同样的问题。 就我而言,删除运行配置就足够了( Run -> Edit Configurations -> Remove Configuration )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM