0

I will often write very small scripts for personal use (no need to package and distribute). I'd like to use PyCharm when writing these and I'd like to call the script without a .py extension. I can't seem to find a way to create a python script in PyCharm without the extension. I just want it to have a shebang (#!) line, and be directly executable. I don't want to have to execute "python foobar.py", but just "./foobar" instead.

Edit: A workaround is that I can create the file without the .py extension outside of PyCharm and then open it up in PyCharm. But the end goal is to have PyCharm create the file itself and not slap a .py on the end of the name. (This is on Unix, btw.)

Edit2: It is now clear to me that people ignore the question and the tag and just read the description. My next question will repeat that actual question in the description. Sorry for the confusion.

Brian Taylor
  • 660
  • 5
  • 11

2 Answers2

3

The question appears to be how to create a Python file without .py extension using PyCharm (3.0.2) so that syntax highlighting and code completion would be still available:

  • From menu: File | New | File.
  • Dialog pops up: "Enter a new file name:". Enter test.
  • Another dialog pops up: "Register New File Type Association". Select Python files.
iljau
  • 2,151
  • 3
  • 22
  • 45
  • This is on linux and/or Mac OS X. The shebang works fine. What I really want is to create a "foobar" file from PyCharm without if forcing the filename to end in ".py". – Brian Taylor Jan 24 '14 at 19:23
  • 1
    He is asking how to create a Python file without .py extension in PyCharm. – RemcoGerlich Jan 24 '14 at 19:34
  • 2
    @iljau: If you remove those first two sections of this answer and leave the final part which correctly answers the question, I'll award you the checkmark. Thanks for the tip. It seems weird that I have to create a file association in order to do this. I can just picture some registry of file extensions in PyCharm cluttered with a bunch of one-off script names. – Brian Taylor Jan 24 '14 at 20:37
-2

You can convert your Python file into an independent executable file using the Nuitka compiler.

cjh
  • 866
  • 4
  • 16