You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> You can also open the Python Environments window by selecting the Solution Explorer window and using the Ctrl+K, Ctrl+` keyboard shortcut. If the shortcut doesn't work and you can't find the Python Environments window in the menu, it's possible you haven't installed the Python workload. See [How to install Python support in Visual Studio](installing-python-support-in-visual-studio.md) for guidance about how to install Python.
29
+
> You can also open the Python Environments window by selecting the Solution Explorer window and using the **Ctrl+K, Ctrl+`** keyboard shortcut. If the shortcut doesn't work and you can't find the Python Environments window in the menu, it's possible you haven't installed the Python workload. See [How to install Python support in Visual Studio](installing-python-support-in-visual-studio.md) for guidance about how to install Python.
30
30
31
31
2. The environment's **Overview** tab provides quick access to an **Interactive** window for that environment along with the environment's installation folder and interpreters. For example, select **Open interactive window** and an **Interactive** window for that specific environment appears in Visual Studio.
32
32
33
-
3. Now, create a new project with **File** > **New** > **Project**, selecting the **Python Application** template. In the code file that appears, paste the following code, which creates a cosine wave like the previous tutorial steps, only this time plotted graphically. Alternatively, you can use the project you previously created and replace the code.
33
+
3. Now, create a new project with **File** > **New** > **Project**, selecting the **Python Application** template. In the code file that appears, paste the following code, which creates a cosine wave like the previous tutorial steps, only this time plotted graphically. Alternatively, you can use the project you previously created and replace the code.
34
34
35
35
```python
36
36
from math import radians
@@ -45,7 +45,7 @@ The Python developer community has produced thousands of useful packages that yo
45
45
main()
46
46
```
47
47
48
-
4. With a Python project open, you can also open the Python Environments window from Solution Explorer by selecting and holding (orright-clicking) on Python Environments and selecting **View All Python Environments**
48
+
4. With a Python project open, you can also open the Python Environments window from Solution Explorer by right-clicking**Python Environments**and selecting **View All Python Environments**
@@ -55,7 +55,7 @@ The Python developer community has produced thousands of useful packages that yo
55
55
56
56
## Install packages using the Python Environments window
57
57
58
-
1. From the Python Environments window, select the default environment for new Python projects andchose the **Packages** tab. You will then see a list of packages that are currently installed in the environment.
58
+
1. From the Python Environments window, select the default environment for new Python projects andchoose the **Packages** tab. You will then see a list of packages that are currently installed in the environment.
59
59
60
60

61
61
@@ -71,7 +71,7 @@ The Python developer community has produced thousands of useful packages that yo
71
71
72
72
> [!NOTE]
73
73
> A small progress bar might appear underneath the environment to indicate that Visual Studio is building its IntelliSense database for the newly-installed package. The **IntelliSense** tab also shows more detailed information. Be aware that until that database is complete, IntelliSense features like auto-completion and syntax checking won't be active in the editor for that package.
74
-
>
74
+
>
75
75
> Visual Studio 2017 version 15.6and later uses a different and faster method for working with IntelliSense, and displays a message to that effect on the **IntelliSense** tab.
Copy file name to clipboardExpand all lines: docs/python/tutorial-working-with-python-in-visual-studio-step-06-working-with-git.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Visual Studio provides direct integration with local Git repositories and remote
21
21
22
22
This article provides a basic overview of creating a local Git repository for an existing project, and familiarizing yourself with some of Visual Studio's Git-related features.
23
23
24
-
1. With a project open in Visual Studio, such as the project from the [previous step](tutorial-working-with-python-in-visual-studio-step-05-installing-packages.md), select and hold (or right-click) the solution and select **Add Solution to Source Control**. Visual Studio creates a local Git repository that contains your project code.
24
+
1. With a project open in Visual Studio, such as the project from the [previous step](tutorial-working-with-python-in-visual-studio-step-05-installing-packages.md), right-click the solution and select **Add Solution to Source Control**. Visual Studio creates a local Git repository that contains your project code.
25
25
26
26
1. When Visual Studio detects that the project is managed in a Git repository Git-related controls appear along the bottom right corner of the Visual Studio window. The controls show pending commits, changes, the name of the repository, and the branch. Hover over the controls to see additional information.
Copy file name to clipboardExpand all lines: docs/python/visual-studio-ide.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ Some of the popular features in Visual Studio that help you to be more productiv
52
52
53
53
-[Refactoring](refactoring-python-code.md)
54
54
55
-
By selecting and holding (or right-clicking) on a piece of code and selecting **Quick actions and Refactorings**, Visual Studio provides you with operations such as intelligent renaming of variables, extracting one or more lines of code into a new method, changing the order of method parameters, and more.
55
+
By right-clicking on a piece of code and selecting **Quick actions and Refactorings**, Visual Studio provides you with operations such as intelligent renaming of variables, extracting one or more lines of code into a new method, changing the order of method parameters, and more.
56
56
57
57

58
58
@@ -89,8 +89,8 @@ Some of the popular features in Visual Studio that help you to be more productiv
89
89
::: moniker-end
90
90
91
91
-[Collaborate using Visual Studio](/visualstudio/liveshare/)
92
-
93
-
Visual Studio Live Share enables you to collaboratively edit and debug with others in real time, regardless of what programming language you're using or app types you're building.
92
+
93
+
Visual Studio Live Share enables you to collaboratively edit and debug with others in real time, regardless of what programming language you're using or app types you're building.
Copy file name to clipboardExpand all lines: docs/python/working-with-c-cpp-python-in-visual-studio.md
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -97,19 +97,19 @@ Follow the instructions in this section to create two identical C++ projects nam
97
97
98
98
1. Make sure the `PYTHONHOME` environment variable isset to the Python interpreter you want to use. The C++ projects in Visual Studio rely on this variable to locate files such as*python.h*, which are used when creating a Python extension.
99
99
100
-
1. Select and hold (or right-click) the solution in**Solution Explorer**and select **Add**>**New Project**. A Visual Studio solution can contain both Python and C++ projects together (which is one of the advantages of using Visual Studio for Python).
100
+
1. Right-click the solution in**Solution Explorer**and select **Add**>**New Project**. A Visual Studio solution can contain both Python and C++ projects together (which is one of the advantages of using Visual Studio for Python).
101
101
102
102
1. Search on "C++", select **Empty project**, specify the name "superfastcode" ("superfastcode2"for the second project), and select **OK**.
103
103
104
104
> [!Tip]
105
105
> With the **Python native development tools** installed in Visual Studio, you can start with the **Python Extension Module** template instead, which has much of what's described below already in place. For this walkthrough, though, starting with an empty project demonstrates building the extension module step by step. Once you understand the process, the template saves you time when writing your own extensions.
106
106
107
-
1. Create a C++filein the new project by selecting and holding (orright-clicking) the **Source Files** node, then select **Add**>**New Item**, select **C++ File**, name it `module.cpp`, and select **OK**.
107
+
1. Create a C++filein the new project by right-clicking the **Source Files** node, then select **Add**>**New Item**, select **C++ File**, name it `module.cpp`, and select **OK**.
108
108
109
109
> [!Important]
110
110
> A filewith the *.cpp* extension is necessary to turn on the C++property pages in the steps that follow.
111
111
112
-
1. Select and hold (or right-click) the C++ project in**Solution Explorer**, select **Properties**.
112
+
1. Right-click the C++ project in**Solution Explorer**, select **Properties**.
113
113
114
114
1. At the top of the **Property Pages** dialog that appears, set**Configuration** to **All Configurations**and**Platform** to **Win32**.
115
115
@@ -126,14 +126,14 @@ Follow the instructions in this section to create two identical C++ projects nam
126
126
|**Linker**>**General**|**Additional Library Directories**| Add the Python *libs* folder containing *.lib* files as appropriate for your installation, for example, `c:\Python36\libs`. (Be sure to point to the *libs* folder that contains *.lib* files, and *not* the *Lib* folder that contains *.py* files.) |
127
127
128
128
> [!Tip]
129
-
> If you don't see the C/C++ tab in the project properties, it's because the project doesn't contain any files that it identifies as C/C++ source files. This condition can occur if you create a source file without a *.c* or *.cpp* extension. For example, if you accidentally entered `module.coo` instead of `module.cpp` in the new item dialog earlier, then Visual Studio creates the file but doesn't set the filetype to "C/C+ Code," which is what activates the C/C++ properties tab. Such misidentification remains the case even if you rename the filewith`.cpp`. To set the filetype properly, select and hold (orright-click) the filein**Solution Explorer**, select **Properties**, then set**File Type** to **C/C++ Code**.
129
+
> If you don't see the C/C++ tab in the project properties, it's because the project doesn't contain any files that it identifies as C/C++ source files. This condition can occur if you create a source file without a *.c* or *.cpp* extension. For example, if you accidentally entered `module.coo` instead of `module.cpp` in the new item dialog earlier, then Visual Studio creates the file but doesn't set the filetype to "C/C+ Code," which is what activates the C/C++ properties tab. Such misidentification remains the case even if you rename the filewith`.cpp`. To set the filetype properly, right-click the filein**Solution Explorer**, select **Properties**, then set**File Type** to **C/C++ Code**.
130
130
131
131
> [!Warning]
132
132
> Always set the **C/C++**>**Code Generation**>**Runtime Library** option to **Multi-threaded DLL (/MD)**, even for a debug configuration, because this setting is what the non-debug Python binaries are built with. With CPython, if you happen to set the **Multi-threaded Debug DLL (/MDd)** option, building a **Debug** configuration produces error **C1189: Py_LIMITED_API is incompatible with Py_DEBUG, Py_TRACE_REFS, and Py_REF_DEBUG**. Furthermore, if you remove `Py_LIMITED_API` (which is required with CPython, but not PyBind11) to avoid the build error, Python crashes when attempting to import the module. (The crash happens within the DLL's call to `PyModule_Create` as described later, with the output message of **Fatal Python error: PyThreadState_Get: no current thread**.)
133
133
>
134
134
> The /MDd option is used to build the Python debug binaries (such as*python_d.exe*), but selecting it for an extension DLL still causes the build error with`Py_LIMITED_API`.
135
135
136
-
1. Select and hold (or right-click) the C++ project and select **Build** to test your configurations (both **Debug**and**Release**). The *.pyd* files are located in the **solution** folder under **Debug**and**Release**, not the C++ project folder itself.
136
+
1. Right-click the C++ project and select **Build** to test your configurations (both **Debug**and**Release**). The *.pyd* files are located in the **solution** folder under **Debug**and**Release**, not the C++ project folder itself.
137
137
138
138
1. Add the following code to the C++ project's *module.cpp* file:
139
139
@@ -273,15 +273,15 @@ Now that you have the DLLs structured as Python extensions, you can refer to the
273
273
274
274
There are two ways to make the DLL available to Python.
275
275
276
-
The first method works if the Python project and the C++ project are in the same solution. Go to **Solution Explorer**, select and hold (orright-click) the **References** node in your Python project, and then select **Add Reference**. In the dialog that appears, select the **Projects** tab, select both the **superfastcode**and**superfastcode2** projects, and then select **OK**.
276
+
The first method works if the Python project and the C++ project are in the same solution. Go to **Solution Explorer**, right-click the **References** node in your Python project, and then select **Add Reference**. In the dialog that appears, select the **Projects** tab, select both the **superfastcode**and**superfastcode2** projects, and then select **OK**.
277
277
278
278

279
279
280
280
The alternate method, described in the following steps, installs the module in the global Python environment, making it available to other Python projects as well. (Doing so typically requires that you refresh the IntelliSense completion database for that environment in Visual Studio 2017 version 15.5and earlier. Refreshing is also necessary when removing the module from the environment.)
281
281
282
282
1. If you're using Visual Studio 2017 or later, run the Visual Studio installer, select **Modify**, select **Individual Components** > **Compilers, build tools, and runtimes** > **Visual C++ 2015.3 v140 toolset**. This step is necessary because Python (for Windows) is itself built with Visual Studio 2015 (version 14.0) and expects that those tools are available when building an extension through the method described here. (Note that you may need to install a 32-bit version of Python and target the DLL to Win32 and not x64.)
283
283
284
-
1. Create a file named *setup.py*in the C++ project by selecting and holding (orright-clicking) the project and selecting **Add**>**New Item**. Then select **C++ File (.cpp)**, name the file`setup.py`, and select **OK** (naming the filewith the *.py* extension makes Visual Studio recognize it as Python despite using the C++file template). When the file appears in the editor, paste the following code into it as appropriate to the extension method:
284
+
1. Create a file named *setup.py*in the C++ project by right-clicking the project and selecting **Add**>**New Item**. Then select **C++ File (.cpp)**, name the file`setup.py`, and select **OK** (naming the filewith the *.py* extension makes Visual Studio recognize it as Python despite using the C++file template). When the file appears in the editor, paste the following code into it as appropriate to the extension method:
285
285
286
286
**CPython extensions (superfastcode project):**
287
287
@@ -360,7 +360,7 @@ After you've made the DLL available to Python as described in the previous secti
360
360
[fast_tanh2(x) for x in d] (PyBind11 C++ extension) took 0.204 seconds
361
361
```
362
362
363
-
If the **Start Without Debugging** command is disabled, select and hold (orright-click) the Python project in**Solution Explorer**and select **Set as Startup Project**.
363
+
If the **Start Without Debugging** command is disabled, right-click the Python project in**Solution Explorer**and select **Set as Startup Project**.
364
364
365
365
1. Try increasing the `COUNT` variable so that the differences are more pronounced. A **Debug** build of the C++ module also runs slower than a **Release** build because the **Debug** build is less optimized and contains various error checks. Feel free to switch between those configurations for comparison.
366
366
@@ -371,7 +371,7 @@ After you've made the DLL available to Python as described in the previous secti
371
371
372
372
Visual Studio supports debugging Python and C++ code together. This section walks through the process using the **superfastcode** project; the steps are the same for the **superfastcode2** project.
373
373
374
-
1. Select and hold (or right-click) the Python project in**Solution Explorer**, select **Properties**, select the **Debug** tab, and then select the **Debug**>**Enable native code debugging** option.
374
+
1. Right-click the Python project in**Solution Explorer**, select **Properties**, select the **Debug** tab, and then select the **Debug**>**Enable native code debugging** option.
375
375
376
376
> [!Tip]
377
377
> When you enable native code debugging, the Python output window may disappear immediately when the program has completed without giving you the usual **Press any key to continue** pause. To force a pause, add the `-i` option to the **Run**>**Interpreter Arguments** field on the **Debug** tab when you enable native code debugging. This argument puts the Python interpreter into interactive mode after the code finishes, at which point it waits for you to press **Ctrl**+**Z**>**Enter** to exit. (Alternately, if you don't mind modifying your Python code, you can add `import os` and `os.system("pause")` statements at the end of your program. This code duplicates the original pause prompt.)
0 commit comments