简体   繁体   English

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

[英]PyCharm Python project No such file or directory

When trying to run a project in PyCharm I get the following error.尝试在 PyCharm 中运行项目时,出现以下错误。 I have setup the virtualbox, vagrant and all the requirements in the readme file they gave me but when pressing run...我已经在他们给我的自述文件中设置了 virtualbox、vagrant 和所有要求,但是当按下运行...

ssh://vagrant@127.0.0.1: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 映射没有正确配置/设置。

I use a Mac OS X 10.9.2 and latest PyCharm IDE.我使用 Mac OS X 10.9.2 和最新的 PyCharm IDE。

Started having the same issue after upgrading to PyCharm 3.4 - before that everything was working fine and after the update the same error.升级到 PyCharm 3.4 后开始遇到同样的问题 - 在此之前一切正常,更新后出现相同的错误。 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.还通过更新路径映射来修复:转到运行/调试配置并手动定义路径映射 - 本地路径应该是您的 Django 项目的路径,而远程路径是指向流浪虚拟机中项目的路径。

I solved the problem by simply removing .idea folder.我通过简单地删除.idea文件夹解决了这个问题。 You can try also this way.你也可以试试这种方式。

Another way to add the project context root in the preferences.在首选项中添加项目上下文根的另一种方法。

Preferences -> Project Structure -> Add Context Root

在此处输入图片说明

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;我发现问题是虚拟机中的映射文件夹不再可访问; ls shows 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/

The solution is do a vagrant reload .解决方案是做一个vagrant reload After this the moved folder is mapped correctly.在此之后,移动的文件夹被正确映射。

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”目录来解决问题,然后选择替换。

I faced the same problem and I solved it as follows我遇到了同样的问题,我解决了如下

Fİle > Settings > project ["your project name"] > Python Interpretor >文件 > 设置 > 项目 [“您的项目名称”] > Python 解释器 >

Add Interpretor > System Interpretor > Apply添加解释器 > 系统解释器 > 应用

I try it and its working but you can chose local interpretor it can be work.我尝试了它并且它可以工作,但是您可以选择本地解释器它可以工作。

Since you mention that your setup involves virtual box and vagrant, you may need to update the path mappings in your Vagrantfile.由于您提到您的设置涉及虚拟框和流浪者,您可能需要更新 Vagrantfile 中的路径映射。 In my case, adding synced paths between the host and vagrant like就我而言,在主机和流浪者之间添加同步路径,例如

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

then a vagrant reload and a Pycharm restart solved the problem.然后vagrant reload和 Pycharm 重启解决了这个问题。

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 configuation your running .py!如果您的所有设置都正确,则可能是 pycharm 版本的问题,并且您也会遇到此问题,您可以在运行 .py 的编辑配置中执行此操作!

在此处输入图片说明

This can also occur if you delete and subsequently recreate a file in your project where both files have the same name.如果您在项目中删除并随后重新创建两个文件具有相同名称的文件,也会发生这种情况。 For example:例如:

  • create a file in the project named foo.py .在项目中创建一个名为foo.py的文件。
  • run foo.py in PyCharm.在 PyCharm 中运行foo.py
  • delete the file foo.py删除文件foo.py
  • create a new file named foo.py创建一个名为foo.py的新文件
  • try to run the new foo.py尝试运行新的foo.py

I had the exact same issue and what happened to me (I am a very new PyCharm user) is that my "working directory" was pointing to the wrong path where my file was located.我遇到了完全相同的问题,发生在我身上的事情(我是一个非常新的 PyCharm 用户)是我的“工作目录”指向了我的文件所在的错误路径。 I fixed this by right clicking on my ".py" file and selecting "Edit Run Configuration:'pyfile" and adjusting my "working directory" to point to where my file was located.我通过右键单击我的“.py”文件并选择“编辑运行配置:'pyfile”并调整我的“工作目录”以指向我的文件所在的位置来解决这个问题。 Hope this works for anyone who runs into a similar issue.希望这适用于遇到类似问题的任何人。

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

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