2

I set up an environment to write Python 3 Code in my emacs (25.2.2) using python-mode and Elpy on Ubuntu 18.04. Strangely every time I use Python --> Send --> Execute Buffer the program is executed twice. It doesn't matter whether I use the mapped key (F6) or go via the menu.

My code in the relevant parts (it's not doing much so far, I'm mostly trying to learn using emacs as an IDE):

import sys

class MyClass:
    def __init__(self, argv):
        # Does something...    

    def __call__(self, x):
        print("Call was called") # But is never called

if __name__ == "__main__":
    print('~~~~Start~~~~')
    # Does not much more
    print('~~~~End~~~~')

The result looks like that:

>>> ~~~~Start~~~~
~~~~End~~~~
>>> ~~~~Start~~~~
~~~~End~~~~

Disclaimer: I'm very new to emacs, so please excuse if the question doesn't have enough information. I'm willing to provide - just need to know how.

Edit (1): Tried to run a simple Hello world program:

if __name__ == '__main__':
    print("Hello World")

Same result:

>>> Hello World
>>> Hello World
  • Does this happen when using emacs -Q? I believe a minimal setup would require the following commands (package-initialize) (require 'package) (package-refresh-contents) (pyvenv-activate "/path/to/venv/") (elpy-enable) – Lorem Ipsum Jan 25 at 14:17
  • You might also check the elpy-config. – Lorem Ipsum Jan 25 at 14:19
  • It's strange your code is executing if __name__ == "__main__": block. Did you try an even simpler code? Did it execute twice? You can execute your code with C-c C-c (or elpy-shell-send-buffer). And if you post your actual code, it will be easier for people to help. – adl Jan 25 at 22:01
  • @LoremIpsum - what to check in the elpy-config? – Qohelet Jan 26 at 18:35
  • 1
    Please add which OS you are using – npostavs Jan 28 at 14:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.