Skip to content
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

Python configuration in Spacemacs #16298

Open
LittFlower opened this issue Mar 3, 2024 · 5 comments
Open

Python configuration in Spacemacs #16298

LittFlower opened this issue Mar 3, 2024 · 5 comments
Assignees

Comments

@LittFlower
Copy link

Hello everyone! I am newcomer of Spacemacs. And this "issue" is target to get some suggestion not bugs....

Can someone share their Python configuration in Spacemacs? I also have a need to write some small Python scripts for temporary use and large Python projects. I don't want too strict syntax conventions or checks for the former, and I want to write Python code in the left window and test the functionality of code snippets in the right window (Python)? Do you have any good configurations?

Some potentially useful information as follows:

  • I use Arch Linux KDE with Wayland.
  • I use emacs GUI.
  • I have already read the doc of Python Layers but I failed to config better.

I really need some suggestions or reference links about these requirements, and I would be grateful for any help :)

@ryanprior
Copy link
Contributor

ryanprior commented Mar 4, 2024

Hi @LittFlower, great to have you here! I suggest creating a discussion in this repo (link: https://github.com/syl20bnr/spacemacs/discussions) as the Issues are only meant to be used for problems and development, while the Discussions are for open ended questions.

(Here's my answer, and I'll move it into a response in Discussions if you follow my advice above 😄)

My Python configuration is quite short, since the Python layer already has a really useful default configuration. I have this in my Spacemacs dotfile:

   dotspacemacs-configuration-layers
   '((python :variables
             python-backend 'lsp
             python-lsp-server 'pyright
             python-shell-interpreter "ipython"
             importmagic-python-interpreter "python3")
     )

# then later...
(use-package python-pytest :init
    (spacemacs/set-leader-keys-for-major-mode 'python-mode "td" #'python-pytest-dispatch))

I also use direnv with direnv-mode to automatically activate my Python virtual environments.

I use M-x python-pytest-dispatch (which you can see I bind to SPCtd) to run my Python tests during development, and I use M-x spacemacs/python-start-or-switch-repl
(bound to SPCm' by default) to create an interactive Python REPL for experimentation.

Hope this helps! Keep asking questions, and let us know if you have any ideas for contributions you'd like to make.

@LittFlower
Copy link
Author

LittFlower commented Mar 5, 2024

sincerely thank you. I will contribute to Spacemacs if i am able to.

@LittFlower
Copy link
Author

LittFlower commented Mar 8, 2024

@ryanprior Thanks for your help. I have configured my dotfile according your code as follows:

   dotspacemacs-configuration-layers
   '((python :variables
             python-backend 'lsp
             python-lsp-server 'pyright
             python-shell-interpreter "ipython"
             importmagic-python-interpreter "python3"
             )

and I configured this in my user-config():

  ;; python ide 配置
  (use-package pytest :init
    (spacemacs/set-leader-keys-for-major-mode 'python-mode "td" #'python-pytest-dispatch))
  (setq python-shell-completion-native-enable nil)

However, when I typed SPC m ' in a Python script, the following warning popped up in the left window:

Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native-enable’ was t and "ipython" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list.  Native completions have been disabled locally. Consider installing the python package "readline". 

I had searched this warnning and added this code in my user-config() :

(setq python-shell-completion-native-enable nil)

I don't know if this is the best practice, but warning has indeed disappeared. But when I used SPC m ' and tried to interact with the ipython on the right side, things became very strange.

spot

Firstly, I don't know what is in the lower half of the window in the picture, as it occasionally pops up when I write the script. Secondly, the iPython interaction environment on the right is very abnormal, as it seems to copy the last character and repeat my input before giving output, and the preceding sequence number is skipped And cannot share the code content on the left side.

I have no idea about this. can you give me more advice? :)

here is my dotfile.

@ryanprior
Copy link
Contributor

@LittFlower oh my that doesn't look nice.

If you change python-shell-interpreter "ipython" to python-shell-interpreter "python3" does that work any better? I think that ipython support might not be in a good state anymore. I just tried it with "python3" in my Spacemacs and it's working fine with completions (which didn't use to be the case)

@LittFlower
Copy link
Author

LittFlower commented Mar 11, 2024

Wuuuu......Could you read Chinese? Or use a translation tool to view this page? I'm very happy with the configuration in this page. But it is in emacs not spacemacs... How can I use/convert the configuration in spacemacs as a spacemacs-er? @ryanprior

@smile13241324 smile13241324 self-assigned this Mar 30, 2024
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

3 participants