Pycharm在带有../的相对路径中看不到文件 [英] Pycharm does not see files in relative path with ../

查看:1497
本文介绍了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 and 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

我在Linux Mint和Python 2.7上使用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 and 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 and dev/Code/Cross Platform/python/boids/current/experiments.

这篇关于Pycharm在带有../的相对路径中看不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆