2

I'm trying to add Python and the Python scripts directory to the PATH variable. Here is the command I'm writing into CMD (I'm using Windows 8.1):

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")

But CMD returns this:

The filename, directory name, or volume label syntax is incorrect.

Anyway, may please someone give me an example? How should I write command above into windows's CMD?


None of these work:

[Environment]::SetEnvironmentVariable("C:/", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")
[Environment]::SetEnvironmentVariable("Path", "C:/;C:\Python27\;C:\Python27\Scripts\", "User")
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
stack
  • 10,280
  • 19
  • 65
  • 117
  • 1
    have u added python path in windows for executing. If not try this http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7 – shiva Apr 10 '17 at 09:01
  • 3
    Possible duplicate of [How to add to the pythonpath in windows 7?](http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7) – Ansgar Wiechers Apr 10 '17 at 09:15

1 Answers1

3

In windows command prompt:

set PATH=%PATH%;C:\Python27\;C:\Python27\Scripts\

Explanation:

set PATH=%PATH%;  -- takes the current path and sets PATH to it.
C:\Python27\;C:\Python27\Scripts\      -- Adds your directories to the path

Is this what you were after?

Raffe81
  • 141
  • 1
  • 8
  • Thank you, upvote. I entered your command and I think it worked, because there wasn't any error. But you know, I'm trying to use implement [this](https://mitmproxy.org/doc/install.html). Please scroll down to see *"Installation On Windows"* paragraph. Now when I write this command `pip install mitmproxy`, it says *"'pip' is not recognized as an internal or external command, operable program or batch file."*. Any idea? – stack Apr 10 '17 at 09:08
  • In order to use pip you have to install pip - and you can't use pip to install pip because pip is not installed :D ... So install pip first ... – Claudio Apr 10 '17 at 09:30
  • @Raffe81 : could you provide also an example of doing the same from within a Python script? – Claudio Apr 10 '17 at 09:32
  • 1
    @Claudio pip is included in Python 2.7.9+ by default – stack Apr 10 '17 at 09:50
  • import sys sys.path.append("C:\Python27") And then the same for your scripts path. – Raffe81 Apr 10 '17 at 10:10
  • Regarding pip. If it is installed, what folder is it in? Is that folder in your PATH? Also if you just added the directories to your PATH I think you need to open a new command prompt for the changes to be affective. – Raffe81 Apr 10 '17 at 10:12