[英]pycharm ssh interpter No such file or directory
I am using a macbook pro 15 as local machine and I have a remote server running ubuntu 14.04我使用 macbook pro 15 作为本地机器,并且我有一个运行 ubuntu 14.04 的远程服务器
I want to use the remote intepreter to run all the computation but I want to write the code from my local machine.我想使用远程解释器来运行所有计算,但我想从本地机器编写代码。
When I try to run a simple file with pycharm I receive this error:当我尝试使用 pycharm 运行一个简单文件时,我收到此错误:
ssh://donbeo@149.157.140.205:22/usr/bin/python3 -u /Users/donbeo/Documents/phd_code/prova.py
bash: line 0: cd: /Users/donbeo/Documents/phd_code: No such file or directory
/usr/bin/python3: can't open file '/Users/donbeo/Documents/phd_code/prova.py': [Errno 2] No such file or directory
Process finished with exit code 2
I saw few people reporting the same problem but I haven't found a good answer so far.我看到很少有人报告同样的问题,但到目前为止我还没有找到好的答案。 Most of the questions are indeed referring to older versions of pycharm.
大多数问题确实指的是旧版本的pycharm。
It is clear that the file is not in my remote machine because I create it with pycharm in my local one.很明显,该文件不在我的远程机器中,因为我在本地机器中使用 pycharm 创建了它。 I was expecting pycharm to do some sort of synchronisation between the local and remote machine.
我期待 pycharm 在本地和远程机器之间进行某种同步。
To execute your code on remote machine you'll have to perform few steps要在远程机器上执行您的代码,您必须执行几个步骤
Python Version (ssh://login@host:port/path/to/interpreter)
.Python Version (ssh://login@host:port/path/to/interpreter)
。 Package list should be populated with records./
is equivalent to /my/root/path
, /dir
to /my/root/path/dir
etc./
相当于/my/root/path
, /dir
相当于/my/root/path/dir
等。Sometimes you can have everything set up correctly (interpreter, deployment, Path mapping, etc) but PyCharm keeps trying to use your local path on the remote machine .有时您可以正确设置所有内容(解释器、部署、路径映射等),但 PyCharm 一直尝试在远程机器上使用您的本地路径。
If this happens, try this 4 fixes:如果发生这种情况,请尝试以下 4 个修复程序:
File->Invalid Caches / Restart
File->Invalid Caches / Restart
...if the problem is still not fixed: ...如果问题仍未解决:
Preferences->Python Interpreter->Path Mappings
and check the path mappings of the interpreter.Preferences->Python Interpreter->Path Mappings
并检查解释器的路径映射。 They should look more or less like this: ...again, if the previous step didn't work: ...同样,如果上一步不起作用:
Run->Edit Configurations...
and check if the path mappings are correct:Run->Edit Configurations...
并检查路径映射是否正确:ModuleNotFoundError
but the connection seems to work, go to Run->Edit Configurations...->Environment Variables
and add your project's root path to the PYTHONPATH
variable.ModuleNotFoundError
但连接似乎正常,请转到Run->Edit Configurations...->Environment Variables
并将您的项目的根路径添加到PYTHONPATH
变量。I'm running PyCharm 2018.3
我正在运行
PyCharm 2018.3
First, I didn't have the [Errno 2] No such file or directory
problem.首先,我没有
[Errno 2] No such file or directory
问题。 Then I had the problem out of nowhere.然后我突然遇到了这个问题。
The issue arose when I did:当我这样做时出现了问题:
By doing the steps above, I had [Errno 2] No such file or directory
problem.通过执行上述步骤,我遇到了
[Errno 2] No such file or directory
问题。
The reason is that the folder is not automatically synced to the remote server (a bug?), nor could I find a way to configure it to sync.原因是该文件夹不会自动同步到远程服务器(错误?),我也找不到将其配置为同步的方法。 Configuring
Deployment
and Path Mappings
did work, but it's too much manual labor and prone to error.配置
Deployment
和Path Mappings
确实有效,但人工劳动太多,容易出错。
All I had to do is to add a new remote interpreter, despite that identical configurations already exists previously.我所要做的就是添加一个新的远程解释器,尽管之前已经存在相同的配置。 (To be safe, I did remove the old ssh interpreter and the old deployments, also removed .idea folder) Then everything worked as expected.
(为了安全起见,我确实删除了旧的 ssh 解释器和旧部署,还删除了 .idea 文件夹)然后一切都按预期进行。
It can be caused by one of the following:它可能是由以下原因之一引起的:
对于那些遇到“miniconda3/envs/gpu/bin/python: can't open file '///home/.../test.py”这样的问题的人,你可以在pycharm的locality中运行python脚本文件而不是在 pycharm 的服务器中运行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.