PyCharm Python 项目没有那个文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23408449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:55:54  来源:igfitidea点击:

PyCharm Python project No such file or directory

pythonmacosvagrantpycharm

提问by George Taskos

When trying to run a project in PyCharm I get the following error. I have setup the virtualbox, vagrant and all the requirements in the readme file they gave me but when pressing run...

尝试在 PyCharm 中运行项目时,出现以下错误。我已经在他们给我的自述文件中设置了 virtualbox、vagrant 和所有要求,但是当按下运行...

ssh://[email protected]:2222/usr/bin/python -u /Users/gtas/Projects/PythonProj/manage.py runserver 0.0.0.0:8000
bash: line 0: cd: /Users/gtas/Projects/PythonProj: No such file or directory
/usr/bin/python: can't open file '/Users/gtas/Projects/PythonProj/manage.py': [Errno 2] No such file or directory

Process finished with exit code 2

[EDIT]It looks like the VM vagrant mappings are not properly configured/set.

[编辑]看起来 VM vagrant 映射没有正确配置/设置。

Any ideas why this drives me crazy?

任何想法为什么这让我发疯?

I use a Mac OS X 10.9.2 and latest PyCharm IDE.

我使用 Mac OS X 10.9.2 和最新的 PyCharm IDE。

Thanks in advance.

提前致谢。

采纳答案by silentser

Started having the same issue after upgrading to PyCharm 3.4 - before that everything was working fine and after the update the same error. Also fixed by updating the path mappings: go to Run/Debug Configurations and manually define the Path mappings - Local path should be the path of your Django project and remote path the path to the project in the vagrant VM.

升级到 PyCharm 3.4 后开始遇到同样的问题 - 在此之前一切正常,更新后出现相同的错误。还通过更新路径映射来修复:转到运行/调试配置并手动定义路径映射 - 本地路径应该是您的 Django 项目的路径,远程路径是指向流浪虚拟机中项目的路径。

回答by Gajen Sunthara

Another way to add the project context root in the preferences.

在首选项中添加项目上下文根的另一种方法。

Preferences -> Project Structure -> Add Context Root

enter image description here

在此处输入图片说明

回答by Fish Monitor

I get this problem whenever I moved a project folder. I've found that the problem is the mapped folder in the virtual machine is no longer accessible; lsshows something like below:

每当我移动项目文件夹时,我都会遇到这个问题。我发现问题是虚拟机中的映射文件夹不再可访问;ls显示如下:

(vagrant) vagrant@ralph-dev:~/src$ ll ls: cannot access ralph: No such file or directory total 8 drwxr-xr-x 3 root root 4096 Jan 11 07:42 ./ drwxr-xr-x 15 vagrant vagrant 4096 Mar 7 09:45 ../ d????????? ? ? ? ? ? ralph/

(vagrant) vagrant@ralph-dev:~/src$ ll ls: cannot access ralph: No such file or directory total 8 drwxr-xr-x 3 root root 4096 Jan 11 07:42 ./ drwxr-xr-x 15 vagrant vagrant 4096 Mar 7 09:45 ../ d????????? ? ? ? ? ? ralph/

The solution is do a vagrant reload. After this the moved folder is mapped correctly.

解决方案是做一个vagrant reload. 在此之后,移动的文件夹被正确映射。

回答by Seal Guo

This problem usually occur when u update the version of python and delete the old dir of python.

这个问题通常发生在你更新python版本并删除python的旧目录时。

May be u can solve the problem by creating a new project with pycharm and copy all the files in a hiding dir named ".idea" in your new project dir to your old projects' "/.idea" dir,and choose replace.

也许您可以通过使用pycharm创建一个新项目并将新项目目录中名为“.idea”的隐藏目录中的所有文件复制到旧项目的“/.idea”目录来解决问题,然后选择替换。

回答by user2275693

Since you mention that your setup involves virtual box and vagrant, you may need to update the path mappings in your Vagrantfile. In my case, adding synced paths between the host and vagrant like

由于您提到您的设置涉及虚拟框和流浪者,您可能需要更新 Vagrantfile 中的路径映射。就我而言,在主机和流浪者之间添加同步路径,例如

config.vm.synced_folder "../code_folder", "/home/vagrant/code_folder"

then a vagrant reloadand a Pycharm restart solved the problem.

然后一个vagrant reload和 Pycharm 重启解决了这个问题。

回答by ahbon

I solved the problem by simply removing .ideafolder. You can try also this way.

我通过简单地删除.idea文件夹解决了这个问题。你也可以试试这种方式。

回答by RyanOf

if your all setting is right, it may be the issue of pycharm version and you also get this problrm, you can do like this in of Edit configuationyour running .py!

如果您的所有设置都正确,则可能是 pycharm 版本的问题,并且您也会遇到此问题,您可以在运行 .py的编辑配置中执行此操作!

enter image description here

在此处输入图片说明