1978 views
# **CS200 VSCode and Python Setup Guide** # **Installing VSCode** In this class, we will be using Visual Studio Code (VSCode) as our primary code editing app for Python. Please follow the instructions on [this official website](https://code.visualstudio.com/docs/setup/setup-overview) for how to set up the software on your computer. Next, we will set up the IDE (Integrated Development Environment, i.e. code editing app) for our purposes. Post questions on EdStem (you can post publicly regarding the setup questions) if you have any troubles or questions setting up the software! We’re happy to help. _You may use a different IDE if you wish, but note that our staff will only support / help with VSCode._ # Downloading Python In our class, we will be using **Python 3.10**. To install it, do the following: 1. Visit **[this page](https://www.python.org/downloads/release/python-31011/#Files)** and scroll down to the **Files** section. Then, select the download link that matches your system--the most common options are shown here: ![](https://docs.cs200.io/uploads/48288cc1-a531-4465-bdfb-77dbc3ef6f16.png) 2. Run the installer once you have downloaded it. You do not need to change any settings in the installation--all of the default options should be fine. # **Download the VSCode Python Extension** VSCode is designed to support a huge number of languages using *extensions*. To install VSCode's Python extensions, do the following: 1. Go to the **“Extensions”** tab on VSCode (located on the left-hand side of the IDE). 2. At the top of the sidebar that pops up, search for **“Python”** in the **Search Extensions in MarketPlace**. You should see a few options pop up, which look like this: ![](https://docs.cs200.io/uploads/d89d3160-d3c6-442b-8321-5c31243a1d73.png) 4. Select the option that looks like the one in the figure (the one that includes the word **“Pylance”** in the description), and click **Install**. 5. Your Python extension should be set up, yay! # Testing your Python setup To make sure your Python set up is working, we've made a test project you can try out. To use it: 1. Please load **[this test project](https://github.com/brown-csci0200/hw00-setup)** by following the **[Python stencil setup guide](https://docs.cs200.io/s/python-stencil-setup-guide#)**. 2. Make sure you are able to **run the tests** in the setup project, following **[these instructions](https://docs.cs200.io/python-stencil-setup-guide?both#Running-tests)**. <!-- These steps make sure that you have configured Conda correctly above and that your VSCode is set up for our Python assignments. First, get our starter code from [here](https://drive.google.com/file/d/12_CIDKDqGhp3FsBfKGJ7ly0WOGlNgn6f/view?usp=sharing). Make sure to open this zip file once it’s downloaded so that the folder appears on your computer. Open the HW00-SETUP folder in VSCode (File → Open folder and navigate to the HW00-setup folder). The left side of your window should look like this: ![](https://lh5.googleusercontent.com/zJrh-AF2KnnXIxdOFOoDzcHPwLAB-3vUxLZ8hRIrwtcWeb0__tYeSEk0gN74Sx6GV_gc7ihFczQkNtoISNGhT-DI9cMCeAm_9dNDqu1b8Aa5YwgeGvUwCLrGUophpwrOHmqDxuhnOxs5An47oQNBrks) **First, make sure that you’ve selected the conda environment as your interpreter as described in the last section, otherwise these next steps won’t work!** Open `image_lib.py` by double-clicking on it and then open a terminal window. ``` ``` The command line should have `(cs200-env)` before your username, indicating that you are in our cs200 conda virtual environment. If this isn’t the case, run `conda activate cs200-env`. Type: python image_lib.py --text 'REPLACE THIS WITH YOUR OWN TEXT' If an image appears with your text on it, you have successfully run this file!  If you encounter errors, specifically (“No module named…”), see the [Troubleshooting](https://docs.google.com/document/d/1ftFKMe5o91Izv9zunA5iMLjuNjnEjk1FIyRoOFl4UAU/edit#bookmark=id.pdrc7ggdprn0) section below.   --> <!-- \ | | | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | **_Note:_** __ if ever you need to install other Python packages in this environment, you can use the command`conda install -c conda-forge [package name]` | --> <!--# **Troubleshooting** In this section, we’ve listed the most common errors we’ve experienced and some fixes.  If you run into issues, please check this section first! ### ‘No module named PIL’ (or similar) This means that python can't find a library needed by our project. Try each of the following steps, in order: - (MacOS only) In the VSCode menu, select  **View** → **Command Palette**.  In the menu that opens, type “user settings” and click “Preferences: Open User Settings” from the options that come up. In the user settings search box, type “`terminal.integrated.inheritEnv`” and uncheck the checkbox, which should look like this: ![](https://lh5.googleusercontent.com/hfMMoPK6dlggdRNS-hactczHZBumG7qR-FkoMqN7Ji1bX2YedaNSekZnMyB9yBQlrCy_pAD5IN1uDEix-T_n72CFPapmIob3fv3ArRVvT-9oea5T2WqMRGXlR4okw5Fduy6Mo6Ap1KqlzMKInyfI354) - (on all systems) Restart VSCode and try again - (on all systems) run `conda deactivate` **_twice_** (or until running `conda info` shows that the active environment is None) and then `conda activate cs200-env`  - (on all systems) after doing the above steps, try the python command above again. Also try running `python3 image_lib.py –-text 'REPLACE THIS WITH YOUR OWN TEXT'` instead If none of that works, follow the [advanced ](https://docs.google.com/document/d/1ftFKMe5o91Izv9zunA5iMLjuNjnEjk1FIyRoOFl4UAU/edit#heading=h.pi0l32zezfft)instructions below.  **You should _not_ be trying to install anything via pip to resolve this issue – please post on Ed if this troubleshooting doesn’t work.** ### If Pytest doesn’t find your tests - Make sure your entire workspace is only the HW00-SETUP folder (for hw0), or, for other homeworks/labs, the folder that contains your stencil repository (sometimes, Pytest struggles when there are multiple files with the same name in a workspace) - Double-check that you are using the cs200-env environment - If there is a folder called `__pycache__` or `.pytest_cache` anywhere in your workspace, delete it - In the terminal, with the cs200-env environment activated, run `conda update --all` and then try discovering the tests again *** # **Advanced troubleshooting for image\_lib.py** **Follow these instructions only if the basic troubleshooting did not help** Open the file called `hello_world.py` and open a new terminal. Make sure the cs200-env is activated in the terminal (run `conda activate cs200-env` if not) ![](https://lh5.googleusercontent.com/gQjRvEUe2qAWUXoF3OV0Pzepr2cLVCXWvRbK5RkEsMT3qeXkJiHCjnq8PE3n9JNp8Z4217xeu3cWMCm6F8F0-36I4LnqsKsLjERKAxz6A9Xc4M1asQXZfWWHAy_-fnkzmBFb8IMV_Z1655z_s5Ideuw) Run hello\_world.py using the “play” button near the top-right of the VSCode window: ![](https://lh3.googleusercontent.com/gBkMWtLtqbbaS1ATdoxoFfjn17b1KBc3OUmU_vz22kUiIGbygbjbohiY1AmitdgR7alaBmPMHalI1QIk9CKBhsaKYyPFS5aCAlHgdiArO52upYgsjNQJEN1Ohn4kRz3vOzxSgIDlw3L8A1Chcd0CakE) The terminal should have the command that was used to run this file. Replace the end of the command (the path to the hello\_world.py file) with the `image_lib.py --text 'REPLACE THIS WITH YOUR OWN TEXT'` , keeping the beginning (what is called the path to the Python interpreter) the same.  ![](https://lh3.googleusercontent.com/zJL6wma7kCn5vQ5dsr7Ewcv9q2lTT-NrS27HheKfvfMXZNVHbmIknDpdq63AFsv6X3yZB3_NqeygjHgXjGCSr1FFh90dzfbkFxirRQu5DZRQQFtMlRZ9LVDfkgkjxT1fKH3-GDFaBBDBsE9Ya_MlYPk) If this works, it is a way that you can run files in the terminal using the correct Python installation that is in the conda environment. --> *** _Please let us know if you find any mistakes, inconsistencies, or confusing language in this or any other CS200 document by filling out the_ [anonymous feedback form](https://docs.google.com/forms/d/e/1FAIpQLSdEK-ttEPd8atXbZBKY8BwUEU4_vXE-5etuVVJDcmIHKXMs7A/viewform)! _(you do have to sign in, but we don’t see it)_