0

I have got simple pcov.py script in PyCharm using optparse

from optparse import OptionParser

As I understand PyCharm has every project in its own virtual environment. My package has the following packages installed (Project: pcov.py > Project interpreter):

  • argparse
  • pip
  • setuptools
  • wheel
  • wsgiref

My project works fine within PyCharm in respect to parsing command line options:

parser = OptionParser(usage=usage)
...
parser.add_option("-z", action="store_true", dest="clean_build",
                  help="Clean all intermediate files")
...

Sadly, it doesn't when I try to run it standalone (from the command line) saying to me incomprenesible:

./pcov.py -z

[the pcov.py hangs here and I had to kill it with Ctrl-C]

from: can't read /var/mail/optparse
./pcov.py: line 9: syntax error near unexpected token ('
./pcov.py: line 9: def pselect(choices):'

Note that PyCharm never complains of no syntax errors and PyCharm handles -z command line option nicely.

I thought at first that I have to install some more package globally', but I didn't findoptparse' python package (pip search optparse) showed me no exact match.

Thus my questions:

1) What packages I have to install (pip install ) to make my pcov.py script running as it does under PyCharm ?

2) Is there an automated way 'to deliver' the PyCharm working script as a standalone Python script?

Using PyCharm CE 2017.0, Debian 8 jessie, python 2.7

  • How have you set project interpreter? – gonczor Jan 15 '18 at 15:45
  • In PyCharm Preferences > Project : pcov.py > Project interpreter selected Show all , and selected /usr/bin/python – Vladimir Zolotykh Jan 15 '18 at 18:41
  • Then it's your system interpreter, not one in virtual environment. I can describe in some detail how to configure it in a few moments. Meanwhile you can try to create a virtual environment with pycharm yourself. – gonczor Jan 15 '18 at 18:58
  • I thought the interpreter is the same for all PyCharm projects (in my case it is Python 2 or Python 3). Each virtual environments has their own set of installed packages in that respect they differ – Vladimir Zolotykh Jan 15 '18 at 20:15
  • My hunch was that my script would work as good standalone as it now does within PyCharm as soon as I make my `global' environment similar to that of PyCharm. – Vladimir Zolotykh Jan 15 '18 at 20:56
  • 1
    I ashamed! I have just added #!/usr/bin/env python at the beginning of my script and it solved the problem. – Vladimir Zolotykh Jan 16 '18 at 07:34

0 Answers0