简体   繁体   English

在PyCharm中运行Docker映像会导致“无效的卷规范”

[英]Running a Docker image in PyCharm causes “Invalid volume specification”

I am trying to run a project based on a Docker Image (Tensorflow, following instructions from this tutorial ) as described in this blog . 我正在尝试运行一个基于Docker映像的项目(Tensorflow,按照本教程的说明进行操作),如本博客所述 The Docker is running fine, but I'm unable to import it in PyCharm (professional, does not work in community version). Docker运行良好,但是我无法将其导入PyCharm(专业,在社区版本中不起作用)。 I get the following error message: 我收到以下错误消息:

Error running main: Can't run remote python interpreter: {"message":"Invalid bind mount spec \\"C:/Path-to-project/Project-name:/opt/project:rw\\": Invalid volume specification: 'C:/Path-to-project/Project-name:/opt/project:rw'"} 运行main时出错:无法运行远程python解释器:{“ message”:“无效的绑定安装规范\\” C:/项目路径/项目名称:/ opt / project:rw \\“:无效的卷规范: 'C:/项目路径/项目名称:/ opt / project:rw'“}

How to solve this? 如何解决呢?

This is a Windows Linux path problem. 这是Windows Linux路径问题。 To solve it, change project paths to the Docker file to /c/Path-to-project/Project-name (with a lower case c and forward slashes) in order to solve this problem. 要解决此问题,请将Docker文件的项目路径更改为/c/Path-to-project/Project-name (使用小写的c和正斜杠)以解决此问题。 Inspired by this link . 受此链接启发。

I solved this problem as follows: 我解决了这个问题,如下所示:

  1. Go to: File -> Settings -> Project -> Project Interpreter -> Your docker interpreter -> Path mappings ; 转到: File -> Settings -> Project -> Project Interpreter -> Your docker interpreter -> Path mappings ;
  2. Add row: {'Local path': 'C:', 'Remote path': '/c'} (replace to your drive with project; if you use this interpeter for several projects from differen drives then add them all); 添加行: {'Local path': 'C:', 'Remote path': '/c'} (用项目替换为驱动器;如果将此插值器用于来自不同驱动器的多个项目,则将它们全部添加);
  3. Go to: Run -> Edit Configurations -> Your configuration -> Docker container settings -> '...' -> Volume bindings ; 转到: Run -> Edit Configurations -> Your configuration -> Docker container settings -> '...' -> Volume bindings
  4. Select row with project's binding (example: {'Container path': '/opt/project', 'Host path': 'C:\\Users\\_username_\\my_python_project'} ) and press ' Edit '. 选择具有项目绑定的行(例如: {'Container path': '/opt/project', 'Host path': 'C:\\Users\\_username_\\my_python_project'} ),然后按' Edit '。
  5. Press OK -> Apply -> OK . OK -> Apply -> OK If first ' OK ' without changes did not help then replace 'Host path': 'C:\\Users\\_username_\\my_python_project' to 'Host path': '/c/Users/_username_/my_python_project' ; 如果首先不做任何更改的“ 确定 ”没有帮助,则将'Host path': 'C:\\Users\\_username_\\my_python_project''Host path': '/c/Users/_username_/my_python_project'
  6. Run your python configuration. 运行您的python配置。

About : 关于

  • Windows 10 1607 [10.0.14393] Windows 10 1607 [10.0.14393]
  • PyCharm 2016.2.3 PyCharm 2016.2.3
  • Build #PY-162.1967.10, built on September 7, 2016 版本号PY-162.1967.10,建于2016年9月7日
  • JRE: 1.8.0_102-b14 amd64 JRE:1.8.0_102-b14 amd64
  • JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation JVM:Oracle Corporation的Java HotSpot(TM)64位服务器VM

Why PyCharm ignore File -> Settings -> Build, Execution, Deployment -> Docker -> VirtualBox shared folders in Run -> Edit Configurations ? 为什么PyCharm会忽略File -> Settings -> Build, Execution, Deployment -> Docker -> VirtualBox shared folders Run -> Edit Configurations File -> Settings -> Build, Execution, Deployment -> Docker -> VirtualBox shared folders

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

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