-3

I downloaded Visual Studio Code and installed Python following the instructions at https://code.visualstudio.com/docs/python/python-tutorial.

As I chose the Python extension in Visual Studio Code, an installation started, but it told me afterwards that the system install is not supported. Therefore I installed it with Homebrew.

First of all, I seem do not have the green 'run'-button displayed in the installation tutorial above. There I only can run code with right click and 'Run Selection/Line in Python Terminal'.

A simple print('Hello, World!') seems to run properly, but when I try to run a program with more than one line (i.e., more than one instruction) I get multiple error messages that I did not get while using Anaconda before.

For context: I am currently learning to program using Python and follow the book 'Automate the boring stuff with Python'.

The code I try to run is:

#! python3
# mclip.py - A multi-clipboard program.

TEXT = {'agree': """Yes, I agree. That sounds fine to me.""",
'busy': """Sorry, can we do this later this week or next week?""", 'upsell': """Would you consider making this a monthly donation?"""}

import sys, pyperclip

if len(sys.argv) < 2:
    print('Usage: py mclip.py [keyphrase] - copy phrase text')
    sys.exit()

keyphrase = sys.argv[1] # first command line arg is the keyphrase

if keyphrase in TEXT:
    pyperclip.copy(TEXT[keyphrase])
    print('Text for ' + keyphrase + ' copied to clipboard.')
else:
    print('There is no text for ' + keyphrase)

For clarification: Traceback (most recent call last): File "/Users/XXX/Desktop/Python Projects/Ex.py", line 7, in <module> import sys, pyperclip ModuleNotFoundError: No module named 'pyperclip' is the error I get.

I just want to use Visual Studio Code properly and I am really not sure why it isn't working or what I did wrong while installing it. (For example, why am I missing the green 'run'-button?!)

5
  • what kind of error you got? Commented May 30, 2020 at 9:12
  • I get multiple error messages—Such as...? Commented May 30, 2020 at 9:12
  • For example: Unable to import 'pyperclip'. Is I installed 'lint' it seems to be a PATH problem. Commented May 30, 2020 at 9:19
  • Does this answer your question? ModuleNotFoundError when importing mysql.connector in for python VS Code Commented Jun 1, 2020 at 23:40
  • I already solved it myself. Thanks anyway! Commented Jun 3, 2020 at 8:15

3 Answers 3

0

There is one syntax error in your code on line 10. sys.exit() should be on the next line. Once that was fixed, it ran fine for me in my Visual Studio Code.

Sign up to request clarification or add additional context in comments.

1 Comment

It seems that there is a Path problem here. See WARNING: The script isort is installed in '/Users/max/Library/Python/3.7/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The scripts epylint, pylint, pyreverse and symilar are installed in '/Users/max/Library/Python/3.7/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
0

It's the indentation error:

if len(sys.argv) < 2:
    print('Usage: py mclip.py [keyphrase] - copy phrase text')
    sys.exit()

sys.exit() should be on the next line.

2 Comments

Re "sys.exit() should be on the next line.": Don't you mean it shouldn't be indented?
OK, in the first revision it wasn't. It is an example of a chameleon question
-1

For displaying a green play button, you have to install the Python extension in Visual Studio Code.

You have made an error. When I ran it I got it. You have to place sys.exit() after enter or on the next line:

sys.exit()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.