Is there any way to parameterize VS Code's python.pythonPath setting?












2















Background: I am a developer on a team that uses Python and uses VS Code heavily. We'd like to be able to share our project.code-workspace but one of the critical settings is python.pythonPath which specifies the Python executable.



Because we use virtualenvs (and at least 2 different operating systems), we can't specify this setting, it will be a different absolute path on various machines.



We also can't not specify, it, though; without it set, many features of the Python extension don't work. As soon as anyone sets it locally in that workspace, the file is modified in version control. We constantly risk someone changing it and then committing their change, breaking it for everyone else.



The result is that we are unable to commit a .code-workspace file because it can't be parameterized.










share|improve this question



























    2















    Background: I am a developer on a team that uses Python and uses VS Code heavily. We'd like to be able to share our project.code-workspace but one of the critical settings is python.pythonPath which specifies the Python executable.



    Because we use virtualenvs (and at least 2 different operating systems), we can't specify this setting, it will be a different absolute path on various machines.



    We also can't not specify, it, though; without it set, many features of the Python extension don't work. As soon as anyone sets it locally in that workspace, the file is modified in version control. We constantly risk someone changing it and then committing their change, breaking it for everyone else.



    The result is that we are unable to commit a .code-workspace file because it can't be parameterized.










    share|improve this question

























      2












      2








      2








      Background: I am a developer on a team that uses Python and uses VS Code heavily. We'd like to be able to share our project.code-workspace but one of the critical settings is python.pythonPath which specifies the Python executable.



      Because we use virtualenvs (and at least 2 different operating systems), we can't specify this setting, it will be a different absolute path on various machines.



      We also can't not specify, it, though; without it set, many features of the Python extension don't work. As soon as anyone sets it locally in that workspace, the file is modified in version control. We constantly risk someone changing it and then committing their change, breaking it for everyone else.



      The result is that we are unable to commit a .code-workspace file because it can't be parameterized.










      share|improve this question














      Background: I am a developer on a team that uses Python and uses VS Code heavily. We'd like to be able to share our project.code-workspace but one of the critical settings is python.pythonPath which specifies the Python executable.



      Because we use virtualenvs (and at least 2 different operating systems), we can't specify this setting, it will be a different absolute path on various machines.



      We also can't not specify, it, though; without it set, many features of the Python extension don't work. As soon as anyone sets it locally in that workspace, the file is modified in version control. We constantly risk someone changing it and then committing their change, breaking it for everyone else.



      The result is that we are unable to commit a .code-workspace file because it can't be parameterized.







      python visual-studio-code






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 23:03









      CoryCory

      1,4562813




      1,4562813
























          1 Answer
          1






          active

          oldest

          votes


















          2














          After some trial-and-error, I found some answers.



          First of all, make sure your virtualenv is visible to VS Code's Python extension



          Two settings appear to control where the Python extension looks for interpreters and environments, python.venvPath and python.venvFolders. The first one is officially documented on the settings reference. I can't find any official documentation for the second one, but there are lots of references to it on the Internet.



          I set my paths as follows. We use virtualenvwrapper.



          I set my paths as follows. We use virtualenvwrapper.



          I recommend setting these at either the User or Workspace level. If you have some team members using different types of virtualenvs, or installing venvs somewhere other than the default, you might want to keep this at the User level so it can be modified by them.



          Second, make sure you haven't accidentally set it somewhere else



          VS Code has multiple settings levels; Default < User < Workspace < Folder.



          In my case (and for many other team members) we had a python.pythonPath setting at the Folder level, which overrides all the others. The Folder level has the highest priority.



          You may need to open and edit settings.json at each level and delete the setting. Once you have done so, VS Code should pick up the path to Python in your virtualenv automatically, meaning you don't have to set it at all.



          If you still must set the python.pythonPath manually . . .



          ... I recommend setting it at the Folder level and hiding ${workspaceFolder}/.vscode from version control. This allows you to:




          • Give each user the ability to set it themselves


          • Give users the ability to set it separately for each project as they switch between projects.



          And again, make sure your team doesn't accidentally change this setting at the Workspace level, so you can keep your project.code-workspace file clean in version control.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310042%2fis-there-any-way-to-parameterize-vs-codes-python-pythonpath-setting%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            After some trial-and-error, I found some answers.



            First of all, make sure your virtualenv is visible to VS Code's Python extension



            Two settings appear to control where the Python extension looks for interpreters and environments, python.venvPath and python.venvFolders. The first one is officially documented on the settings reference. I can't find any official documentation for the second one, but there are lots of references to it on the Internet.



            I set my paths as follows. We use virtualenvwrapper.



            I set my paths as follows. We use virtualenvwrapper.



            I recommend setting these at either the User or Workspace level. If you have some team members using different types of virtualenvs, or installing venvs somewhere other than the default, you might want to keep this at the User level so it can be modified by them.



            Second, make sure you haven't accidentally set it somewhere else



            VS Code has multiple settings levels; Default < User < Workspace < Folder.



            In my case (and for many other team members) we had a python.pythonPath setting at the Folder level, which overrides all the others. The Folder level has the highest priority.



            You may need to open and edit settings.json at each level and delete the setting. Once you have done so, VS Code should pick up the path to Python in your virtualenv automatically, meaning you don't have to set it at all.



            If you still must set the python.pythonPath manually . . .



            ... I recommend setting it at the Folder level and hiding ${workspaceFolder}/.vscode from version control. This allows you to:




            • Give each user the ability to set it themselves


            • Give users the ability to set it separately for each project as they switch between projects.



            And again, make sure your team doesn't accidentally change this setting at the Workspace level, so you can keep your project.code-workspace file clean in version control.






            share|improve this answer




























              2














              After some trial-and-error, I found some answers.



              First of all, make sure your virtualenv is visible to VS Code's Python extension



              Two settings appear to control where the Python extension looks for interpreters and environments, python.venvPath and python.venvFolders. The first one is officially documented on the settings reference. I can't find any official documentation for the second one, but there are lots of references to it on the Internet.



              I set my paths as follows. We use virtualenvwrapper.



              I set my paths as follows. We use virtualenvwrapper.



              I recommend setting these at either the User or Workspace level. If you have some team members using different types of virtualenvs, or installing venvs somewhere other than the default, you might want to keep this at the User level so it can be modified by them.



              Second, make sure you haven't accidentally set it somewhere else



              VS Code has multiple settings levels; Default < User < Workspace < Folder.



              In my case (and for many other team members) we had a python.pythonPath setting at the Folder level, which overrides all the others. The Folder level has the highest priority.



              You may need to open and edit settings.json at each level and delete the setting. Once you have done so, VS Code should pick up the path to Python in your virtualenv automatically, meaning you don't have to set it at all.



              If you still must set the python.pythonPath manually . . .



              ... I recommend setting it at the Folder level and hiding ${workspaceFolder}/.vscode from version control. This allows you to:




              • Give each user the ability to set it themselves


              • Give users the ability to set it separately for each project as they switch between projects.



              And again, make sure your team doesn't accidentally change this setting at the Workspace level, so you can keep your project.code-workspace file clean in version control.






              share|improve this answer


























                2












                2








                2







                After some trial-and-error, I found some answers.



                First of all, make sure your virtualenv is visible to VS Code's Python extension



                Two settings appear to control where the Python extension looks for interpreters and environments, python.venvPath and python.venvFolders. The first one is officially documented on the settings reference. I can't find any official documentation for the second one, but there are lots of references to it on the Internet.



                I set my paths as follows. We use virtualenvwrapper.



                I set my paths as follows. We use virtualenvwrapper.



                I recommend setting these at either the User or Workspace level. If you have some team members using different types of virtualenvs, or installing venvs somewhere other than the default, you might want to keep this at the User level so it can be modified by them.



                Second, make sure you haven't accidentally set it somewhere else



                VS Code has multiple settings levels; Default < User < Workspace < Folder.



                In my case (and for many other team members) we had a python.pythonPath setting at the Folder level, which overrides all the others. The Folder level has the highest priority.



                You may need to open and edit settings.json at each level and delete the setting. Once you have done so, VS Code should pick up the path to Python in your virtualenv automatically, meaning you don't have to set it at all.



                If you still must set the python.pythonPath manually . . .



                ... I recommend setting it at the Folder level and hiding ${workspaceFolder}/.vscode from version control. This allows you to:




                • Give each user the ability to set it themselves


                • Give users the ability to set it separately for each project as they switch between projects.



                And again, make sure your team doesn't accidentally change this setting at the Workspace level, so you can keep your project.code-workspace file clean in version control.






                share|improve this answer













                After some trial-and-error, I found some answers.



                First of all, make sure your virtualenv is visible to VS Code's Python extension



                Two settings appear to control where the Python extension looks for interpreters and environments, python.venvPath and python.venvFolders. The first one is officially documented on the settings reference. I can't find any official documentation for the second one, but there are lots of references to it on the Internet.



                I set my paths as follows. We use virtualenvwrapper.



                I set my paths as follows. We use virtualenvwrapper.



                I recommend setting these at either the User or Workspace level. If you have some team members using different types of virtualenvs, or installing venvs somewhere other than the default, you might want to keep this at the User level so it can be modified by them.



                Second, make sure you haven't accidentally set it somewhere else



                VS Code has multiple settings levels; Default < User < Workspace < Folder.



                In my case (and for many other team members) we had a python.pythonPath setting at the Folder level, which overrides all the others. The Folder level has the highest priority.



                You may need to open and edit settings.json at each level and delete the setting. Once you have done so, VS Code should pick up the path to Python in your virtualenv automatically, meaning you don't have to set it at all.



                If you still must set the python.pythonPath manually . . .



                ... I recommend setting it at the Folder level and hiding ${workspaceFolder}/.vscode from version control. This allows you to:




                • Give each user the ability to set it themselves


                • Give users the ability to set it separately for each project as they switch between projects.



                And again, make sure your team doesn't accidentally change this setting at the Workspace level, so you can keep your project.code-workspace file clean in version control.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 '18 at 23:03









                CoryCory

                1,4562813




                1,4562813
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310042%2fis-there-any-way-to-parameterize-vs-codes-python-pythonpath-setting%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown