归档 | 首页
回到顶部 Back to Top

Python虚拟环境搭建

目录

一、使用Python直接搭建虚拟环境

Archlinux

  1. 搭建:

    python -m venv /*venvname*/
    
  2. 进入:

    source venvname/bin/activate
    
  3. 在当前虚拟环境安装插件:

    pip install /*appname*/
    pip install setuptools(3.12之后版本必需)
    
  4. 退出:

    deactivate
    

Windows

  1. 下载安装windows版python
  2. 下载安装Git for Windows
  3. 用git bash创建虚拟环境

    python -m venv d:/PythonProject
    
  4. 安装插件

    source d:/PythonProject/Scripts/activate
    pip install setuptools
    pip install jedi
    pip install flake8
    pip install autopep8
    

二、Emacs设置

;; ==========python-mode==========
(use-package python
    :mode ("\\.py\\'" . python-mode)
    :interpreter ("python" . python-mode)
    :bind ([f2] . elpy-shell-send-region-or-buffer)
    :config
    (message "Loading Python-mode...DONE")
    )

;; ==========elpy==========
(use-package elpy
    :ensure t
    :defer t
    :init
    (advice-add 'python-mode :before 'elpy-enable)
    ;;    :hook
    ;;    (python-mode . elpy-mode)
    :config
    (cond
      ((eq system-type 'gnu/linux)
       (pyvenv-activate "~/python/")
       (setq elpy-rpc-virtualenv-path 'current))
      ((eq system-type 'windows-nt)
       (pyvenv-activate "D:/PythonProject/")
       (setq explicit-shell-file-name "C:/Program Files/Git/usr/bin/bash.exe"
             shell-file-name "bash.exe"
             python-shell-interpreter "python"
             elpy-rpc-virtualenv-path 'current
             elpy-rpc-python-command "D:/PythonProject/Scripts/python.exe")))
    (message "Loading Elpy...DONE")
    )

作者 © YoursAF

最后更新: 2025-01-07 二 22:36

Built with Emacs 29.3 (Org mode 9.7.18)

冀ICP备17032034号-1