首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从码头运行PyCharm?

如何从码头运行PyCharm?
EN

Stack Overflow用户
提问于 2018-07-12 14:55:21
回答 2查看 5.6K关注 0票数 4

我能够从保存我的Dockerfile的路径构建一个码头映像,其中包含了PyCharm的安装说明。在构建图像时,我能够查看创建的图像列表。然后我输入了docker -pycharm,这是我在码头构建的映像的名称,并且我的容器正在运行。现在我被困在如何从这个容器装载Pycharm了?谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-07-12 20:52:01

好吧,我现在明白你的问题了。您需要能够运行您的主机没有依赖项的python脚本。

另外,管理python依赖关系的一种常见方法是使用维塔列夫虚拟包装器。如果您不熟悉它,并且希望有一种简单的方法来管理python依赖项,那么您应该更多地了解它,因为这可能是最好的解决方案。

使用Docker作为管理python依赖项的一种方法也可以很好地工作,这是一种相对较新的实践,可能正在变得越来越普遍。在这种情况下,您不希望在Docker容器中运行PyCharm。相反,您应该在主机上使用PyCharm进行开发,并使用容器来运行您的python脚本。

用一个例子来说明这是如何工作的最好的方法。为了简单起见,创建一个新文件夹,cd到它,并创建一个简单的python脚本(hello.py):

代码语言:javascript
复制
#!/usr/bin/env python
print("Hello, world!")

现在,我们可以运行以下Docker命令:

代码语言:javascript
复制
$ docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3 python hello.py

该命令将将当前目录作为/usr/src/myapp加载到容器中。当您对项目执行此操作时,应该是您的项目目录。该命令将容器中的workdir设置为/usr/src/myapp,以便我们可以使用相对路径。只需将命令末尾的hello.py更改为要运行的脚本的相对路径。

因为您的项目文件夹是作为卷挂载到容器中的,所以您可以在主机上编辑PyCharm中的代码,并在容器中运行脚本。这个例子使用了默认的python 3容器,但是将上面命令中的图像名称替换为您想要使用的映像的名称非常简单,因为映像已经安装了所需的依赖项。

票数 2
EN

Stack Overflow用户

发布于 2020-02-14 17:45:39

在码头内外运行IDE时存在几个问题。

在带有python解释器的主机上运行PyCharm时,共享代码库可以由

  1. PyCharm的远程解释器功能
代码语言:javascript
复制
- Over SSH: [https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html](https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html)
- Over Docker TCP port: [https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.html](https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.html)
- The code resides on the host, which is necessary for PyCharm to provide static analysis. [https://www.jetbrains.com/help/pycharm/code-inspection.html](https://www.jetbrains.com/help/pycharm/code-inspection.html)
- Whenever you want to run the code, it needs to synced with the remote system. I'm not sure how the synchronization behaves, so I don't know if the syncing is two way, or if PyCharm on the host always overwrites the remote system (docker container) [https://www.jetbrains.com/help/pycharm/configuring-synchronization-with-a-remote-host.html](https://www.jetbrains.com/help/pycharm/configuring-synchronization-with-a-remote-host.html)

  1. 在docker容器中挂载主机目录:
代码语言:javascript
复制
- Docker Desktop on Windows has a lot of limitations when mounting a Windows directory inside the docker container.  
    - The linux container cannot change the permissions of files inside the Windows directory. The files always appear to have the permissions 755 (rwxr-xr-x). If you try to mount your openssh configs or keys inside the linux container, ssh on linux will refuse to use those files because they are insecure. [https://docs.docker.com/v17.09/docker-for-windows/troubleshoot/#permissions-errors-on-data-directories-for-shared-volumes](https://docs.docker.com/v17.09/docker-for-windows/troubleshoot/#permissions-errors-on-data-directories-for-shared-volumes)
    - The linux container will not get filesystem events (inotify) letting it know that files have changed on the file mounted from Windows. If you use `./manage.py runserver` to run Django in development, it would need to poll all the files in the codebase to see if there are any changes. I have not tested Django's polling. If it does not work sufficiently quickly, you may have to restart Django so that it reflects your changes.  [https://william-yeh.net/post/2019/06/inotify-in-containers/](https://william-yeh.net/post/2019/06/inotify-in-containers/)
    - This works much better when the host is a Mac, because the osxfs mounted volumes work better with linux containers. [https://docs.docker.com/docker-for-mac/osxfs/](https://docs.docker.com/docker-for-mac/osxfs/) 
        1. Mounting a directory in the linux container on Windows.

代码语言:javascript
复制
    - SSHFS with WinFSP allows Windows to mount the files over ssh. This requires an ssh server to be installed in the linux container. An NFS or Samba server on the linux container could also be used for file sharing but with similar problems.
    - PyCharm on Windows does not support polling for file changes. If you mount the codebase over ssh, NFS, or SMB, PyCharm will not know if you have added a new file. This is especially an issue if you switch to a different branch for your codebase.

目前,我正在试验在linux容器中运行PyCharm。

  • 使用,您不能使用JetBrains工具箱来安装PyCharm,因为安装它时需要支持fuse内核驱动程序的AppImage。看来docker在这方面正在取得进展,但我的Windows 10版本并不是内部预览版的一部分,所以我还没有测试这些新特性。https://www.infoq.com/news/2019/12/docker-desktop-windows-fuse/
  • 你只需安装吡咯烷酮和运行它。您肯定需要在Desktop的参考资料设置中增加内存和交换。
  • 为了使linux容器能够显示gui应用程序,Windows需要运行xserver (如VcXsrv )。启动之后,可以设置env DISPLAY=localhost:0。通过指定localhost而不仅仅是DISPLAY=:0,您运行的任何gui应用程序都会知道它需要通过TCP连接到VcXsrv,而不是寻找不存在的VcXsrv套接字。
  • 通过在linux容器中运行PyCharm,我也不必考虑Git中的crlf转换设置。https://help.github.com/en/github/using-git/configuring-git-to-handle-line-endings
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51308804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档