Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Setting Up a Local Python Environment Installing Python and Python Libraries Locally Using virtualenv

Chris Nelson
Chris Nelson
4,603 Points

Installing Virtualenv on Windows 8.1

Hello! I'm having a lot of trouble installing virtualenv on windows 8.1.

I've installed python locally and used pip install virtualenv, and that all worked fine. But now I'm having issues naming virtualenv to venv? I'm not exactly sure the correct terms so correct me if I'm wrong. I'm not trying to activate it yet because I still need to do the step before it.

In command prompt I'm typing \c:\python 3.5\lib\venv\virtualenv venv and it's not working. I've tried several different locations and they all say "The file name, directory name, or volume label syntax is incorrect."

I've tried uninstalling and reinstalling python several times now. Can't seem to figure it out!

Help would be very appreciated, thanks

Chris Nelson
Chris Nelson
4,603 Points

It seems like virtualenv installed in: \c:\python 3.5\lib\site-packages\ but when I use that file path to try and name virtualenv to venv I still get the same error from up top.

7 Answers

Chris Nelson
Chris Nelson
4,603 Points
PS C:\Windows\system32> c:\python35\lib\site-packages\virtualenv venv
Using base prefix 'C:\\Python35'
New python executable in venv\Scripts\python.EXE
ERROR: The executable venv\Scripts\python.EXE is not functioning
ERROR: It thinks sys.prefix is 'c:\\windows\\syswow64\\venv' (should be 'c:\\windows\\system32\\venv')
ERROR: virtualenv is not compatible with this system or executable
Note: some Windows users have reported this error when they installed Python for "Only this user" or have multiple versi
ons of Python installed. Copying the appropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem.111
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

It looks like you have a 32-bit vs 64-bit mismatch:

It thinks sys.prefix is 'c:\\windows\\syswow64\\venv' (should be 'c:\\windows\\system32\\venv')

Please verify that you have the correct Python to match your system. Newer systems should be using 64-bit Python. 32-bit should only be needed on some legacy machines.

C:\Users\User>c:\Python27\python.exe
Python 2.7.6 (default, Nov 10 2013, 19:24:18 [MSC v.1500 32 bit (Intel)] on win32
>>> quit()

C:\Users\User>c:\Python35\python.exe
Python 3.5.0 <v3.5.0:374f501f4567, Sep 13 2015, 02:27:37> [MSC v1900 64 bit (AMD)] on win32
>>> quit()
Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The issue is with the directory path name. In some setups, path names with spaces in them, such as "Python 3.5", do not work with all scripts. The best solution would be to re-install Python 3.5 in the directory C:\Python3.5 or C:\Python35

Chris Nelson
Chris Nelson
4,603 Points

Thank you, I had a feeling it might be something like that. I'll give that a try and see how it goes.

Chris Nelson
Chris Nelson
4,603 Points

Still not working after re-installing with a better name. I should rephrase my issue. I have no problem actual installing virtualenv with pip. I just can't seem to run it.

In the video, Kenneth runs virtualenv, names it venv and activates it. I can't do either of these steps on windows.

In c:\python35\lib\site-packages there is a virtualenv python file but no .exe

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

The second item to check is the execution policy:

PS C:\Users\User>
PS C:\Users\User> Get-ExecutionPolicy
Restricted
PS C:\Users\User> Set-ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the
about_Execution_Policies help topic at http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y
PS C:\Users\User> Get-ExecutionPolicy
RemoteSigned

Setting to RemoteSigned should help. You will need run the PowerShell window "As Administrator". Right-click on the PowerShell icon to select this option.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Relooking at your original post:

\c:\python 3.5\lib\venv\virtualenv venv

The leading backslash should be removed:

c:\python 3.5\lib\venv\virtualenv venv

Chris Nelson
Chris Nelson
4,603 Points

Oooh, I've been using command prompt. Not powershell. I had no idea we had to use powershell

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

One method to cut and paste from Windows:

  • highlight the text using left-mouse button
  • hit <Enter> to copy to clipboard
  • if in command window or PowerShell, using right-button to paste
  • if in other window uses Cntl-V to paste.
Chris Nelson
Chris Nelson
4,603 Points

I've changed the execution policy to remote signed, and I get an error when I run PATH: c:\python35\lib\site-packages\virtualenv venv. I'm not sure how to copy and post the error though.

It says it creates python.exe in venv/scripts and says that the computer thinks the prefix is one path but should actually be a different one. Then says virtualenv is not compatible with this system or executable.

Chris Nelson
Chris Nelson
4,603 Points

Ah man, I'll download the right one and re-install. I read somewhere that the 64bit version was buggy. Thanks for your help, I'll let you know if I have any issues. Just to clerify; should I be running c:\python35\lib\site-packages\virtualenv venv OR c:\python35\lib\venv\virtualenv venv?

Thank you Chris

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

It depends on how virtualenv was installed. It should be on your path so you don't need to type the full path. Many installers will add this to your path for you. You may have to check a box during installation to "Add to Path"

Typically, the path would be C:\Python35\Scripts\virtualenv. If not there, then the "site-packages' version (likely installed with 'pip') would work next.

Not sure about the "lib\venv" version as it would seem to be installed as a bundle with the Python package. If so, it should be OK as well.

For each location, you can run with the argument "--version" to see which one is the latest.

Chris Nelson
Chris Nelson
4,603 Points

All sorted Chris, thank you so much.

Chris Nelson
Chris Nelson
4,603 Points

Must have just been the fact I was using 32 bit instead of 64. c:\python34\scripts\virtualenv venv and c:\python34\lib\site-packages\virtualenv venv worked fine either way. Activating it after that was no issue using venv\scripts\activate

I feel like the need for Powershell needs to be stated a bit more, and the changing of the execution policy was smart as well.

Very happy, thank you