Skip to content

python virtual environment activation #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zhangfelix opened this issue Mar 9, 2021 · 4 comments
Closed

python virtual environment activation #774

zhangfelix opened this issue Mar 9, 2021 · 4 comments

Comments

@zhangfelix
Copy link

I'm working in a mac(apple m1).
I used M-x pythonic-activate RET /path/to/virtualenv RET to change the virtual environment in anaconda-mode. But Python Shell, pdb and flycheck use three different environments.

It works fine when I used C-c C-p, in a Python Shell.

>>> import sys
>>> print(sys.path)
['', '/Users/felix/miniforge3/envs/gluon/lib/python38.zip', '/Users/felix/miniforge3/envs/gluon/lib/python3.8', '/Users/felix/miniforge3/envs/gluon/lib/python3.8/lib-dynload', '/Users/felix/miniforge3/envs/gluon/lib/python3.8/site-packages']

But the pdb( python -m pdb test.py) use the python2.7 from the system.

 ['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

While the flycheck use python from homebrew.

Syntax checkers for buffer test.py in python-mode:

First checker to run:

  python-pycompile
    - may enable:    yes
    - executable:    Found at /opt/homebrew/bin/python3
    - next checkers: python-mypy

Checkers that are compatible with this mode, but will not run until properly configured:

  python-flake8 (automatically disabled) reset
    - may enable:         no
    - executable:         Found at /opt/homebrew/bin/python3
    - configuration file: Not found
    - `flake8' module:    Missing; sys.path is ['/opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/opt/homebrew/lib/python3.9/site-packages']
    - next checkers:      python-pylint, python-mypy

  python-pylint (automatically disabled) reset
    - may enable:         no
    - executable:         Found at /opt/homebrew/bin/python3
    - configuration file: Not found
    - `pylint' module:    Missing; sys.path is ['/opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9', '/opt/homebrew/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/opt/homebrew/lib/python3.9/site-packages']
    - next checkers:      python-mypy

  python-pyright (automatically disabled) reset
    - may enable: no
    - executable: Not found

  python-mypy (automatically disabled) reset
    - may enable:         no
    - may run:            t
    - executable:         Not found
    - configuration file: Not found

Flycheck Mode is enabled.  Use C-u C-c ! x to enable disabled
checkers.

--------------------

Flycheck version: 32snapshot (package: 20201228.2104)
Emacs version:    27.1
System:           aarch64-apple-darwin20.2.0
Window system:    ns
@zhangfelix
Copy link
Author

I tried pyvenv, and it works.
I add (require-package 'pyvenv) into init-local.el.
Use M-x pyvenv-activate to specify the virtual environment directory. After that, Python Shell, pdb and flycheck use the same environment.

Maybe It is batter to add pyvenv into default configuration.

@purcell
Copy link
Owner

purcell commented Mar 9, 2021

Thanks for filing this. I don't think I want to prescribe how people should manage their python virtual envs, and locally I use poetry, nix and direnv instead of pyvenv etc.

@zhangfelix
Copy link
Author

You're right, this is more like a special use case. Just record it in case others encounter the same problem.

@purcell
Copy link
Owner

purcell commented Mar 12, 2021

I've updated the note in init-python.el at least. :-)

cdadar pushed a commit to cdadar/emacs.d that referenced this issue Mar 24, 2021
ntdef pushed a commit to ntdef/emacs.d that referenced this issue Dec 26, 2021
harshrc pushed a commit to harshrc/emacs.d that referenced this issue Feb 12, 2022
acmay added a commit to acmay/emacs.d that referenced this issue Dec 14, 2022
* upstream/master: (40 commits)
  Update copyright year
  Clarify why users should update packes regularly
  Don't automatically preview consult ripgrep commands
  Don't remap yank-pop to consult-yank-replace
  init-ocaml: add incantations for using ocamllsp with eglot
  init-ocaml: better handling of merlin-company
  init-ocaml: remove merlin-mode code no longer required since upstream fixes
  Divide code sections consistently
  Remove defunct company-elm package
  Use new dune-format package extracted from this config
  Tweaks to consult config
  Add Emacs 27.2 to CI
  Prefer consult-goto-line to goto-line-preview
  Support company margin icons
  move-dup commands have been renamed
  Zap-up-to-char has been autoloaded for 5 years now
  Pre-declare url-show-status var in startup script
  Update note about using pyvenv, see purcell#774
  Add support for ocaml's "dune" build tool
  Work around selectrum minibuffer height issue
  ...
cdadar pushed a commit to cdadar/emacs.d that referenced this issue Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants