pycharm找不到python路径_Pycharm在带有../的相对路径中看不到文件

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()

I get:

self.image = pygame.image.load("../resources/img/prey.png").convert_alpha()

pygame.error: Couldn't open ../resources/img/prey.png

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()

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

The code that runs self.image=pygame.image.load("../resources/img/prey.png").convert_alpha() is in ./objects

I am using Pycharm Community Edition 2016.1.2 on Linux Mint with Python 2.7.

Any help is appreciated.

EDIT

when running os.getcwd from the command line I get /media/Storage/System and dev/Code/Cross Platform/python/boids/current/experiments

解决方案

Go to Run - Edit Configurations, select your configuration

and change Working directory to /media/Storage/System and dev/Code/Cross Platform/python/boids/current/experiments.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值