pythonic-emacs/anaconda-mode

Can not import packages installed in server_directory when using docker

Closed this issue · 5 comments

Problem

If I connect to a docker container with jedi already installed, Python will ignore the jedi installed in server_directory, but import the one installed default.

Reproduce the problem

Related Emacs configuration

(use-package anaconda-mode
  :hook ((python-mode . anaconda-mode)
         (python-mode . anaconda-eldoc-mode)))

(use-package docker-tramp
  :config
  (progn
    (add-to-list 'tramp-remote-path 'tramp-own-remote-path)))

Steps

  1. Run docker run -i -t pytorch/pytorch:1.9.0-cuda11.1-cudnn8-runtime bash and install socat.
  2. Start Emacs, and C-x C-f /docker:root@{container-id}:{path_to_a_python_file}

The *anaconda-mode* buffer shows:

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting jedi==0.18.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f9/36/7aa67ae2663025b49e8426ead0bad983fee1b73f472536e9790655da0277/jedi-0.18.0-py2.py3-none-any.whl (1.4 MB)
     |████████████████████████████████| 1.4 MB 756 kB/s eta 0:00:01
Collecting service_factory==0.1.6
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/33/15/5beb1df57ec538bfa48f61f34a8de6061139ff7aca0f2bcf30b525bc07cb/service_factory-0.1.6.tar.gz (19 kB)
Collecting parso<0.9.0,>=0.8.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a9/c4/d5476373088c120ffed82f34c74b266ccae31a68d665b837354d4d8dc8be/parso-0.8.2-py2.py3-none-any.whl (94 kB)
     |████████████████████████████████| 94 kB 3.9 MB/s  eta 0:00:01
Building wheels for collected packages: service-factory
  Building wheel for service-factory (setup.py) ... done
  Created wheel for service-factory: filename=service_factory-0.1.6-py3-none-any.whl size=20679 sha256=37aeae7c2e26b9fa324b3dbb3c7304c27ef87b62e6168d3fbce44712625f3e1e
  Stored in directory: /root/.cache/pip/wheels/86/44/d7/e90fe180f78b01754f99bdc850fa68cb503188e08c9dd52758
Successfully built service-factory
Installing collected packages: parso, service-factory, jedi
Successfully installed jedi-0.18.0 parso-0.8.2 service-factory-0.1.6
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
Traceback (most recent call last):
  File "<string>", line 117, in <module>
AssertionError: Jedi version should be >= 0.18.0, current version: 0.17.0

Specifications

Host machine:

  • OS: Manjaro 21.1.5 Pahvo
  • Kernel: x86_64 Linux 5.10.70-1-MANJARO
  • docker 1:20.10.8-1
  • anaconda-mode 20210409.1536
  • docker-tramp 20210729.508

Docker container:

  • which conda gives /opt/conda/bin/conda
  • which python gives /opt/conda/bin/python
  • conda list jedi gives version 0.17.0
  • ls /root/.emacs.d/anaconda-mode/0.1.14-py3/ shows
    jedi                   parso                  service_factory
    jedi-0.18.0.dist-info  parso-0.8.2.dist-info  service_factory-0.1.6.dist-info
    

Thus we can know that anaconda-mode is using the pre-installed jedi instead of the one installed in ${HOME}/.emacs.d/anaconda-mode/.

dakra commented

Does #416 fix this for you?

The code below in anaconda-mode.py cause the server_directory to be add to the end of sys.path. Thus it has has a lower priority and is ignored.

site.addsitedir(server_directory)

One workaround is that

@@ -34,6 +34,7 @@
 if not os.path.exists(server_directory):
     os.makedirs(server_directory)
 site.addsitedir(server_directory)
+sys.path.insert(0, sys.path.pop(-1))

Does #416 fix this for you?

Thank you! I just saw your reply. #416 does the same thing as my workaround.

dakra commented

I just pushed a commit that should fix it then.
Please test and close this issue if it's working.
Thanks for the detailed bug report.

Fixed in 0546c09.