Related
Since updating from Homebrew Python 2.7.11 (from 2.7.10) I'm suddenly unable to test register my package on PyPi from the PyCharm IDE console.
Running (as an "External Tool")
python -B setup.py register -r pypitest
I now get
Traceback (most recent call last):
File "setup.py", line 22, in <module>
from setuptools import setup
File "/usr/local/lib/python2.7/site-packages/setuptools/__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "/usr/local/lib/python2.7/site-packages/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File "/usr/local/lib/python2.7/site-packages/setuptools/dist.py", line 16, in <module>
from setuptools.depends import Require
File "/usr/local/lib/python2.7/site-packages/setuptools/depends.py", line 6, in <module>
from setuptools import compat
File "/usr/local/lib/python2.7/site-packages/setuptools/compat.py", line 17, in <module>
import httplib
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 80, in <module>
import mimetools
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Process finished with exit code 1
I'm not sure how to proceed. I only get this issue if I execute from within my IDE's console. If I do it directly at the system command line (Terminal on OS X) I have no problems.
OS X 10.11.3; Homebrew Python 2.7.11; PyCharm 5.0.3
tl;dr: Fix this issue by doing one of the following:
type hash -r python, OR
log out and log in.
EDIT: An answer to my related question makes it clear what's happening here. When you install a new version of python, you may need to run hash -r python to tell bash to reset the "cached" location to the python executable.
In my case, I was typing python, which was on my $PATH at /usr/local/bin/python. But bash was still using the old cache location /usr/bin/python. So, the old executable was called, but the new path was provided to python in sys.argv[0]. This means that the old executable was running, but the new sys.executable value caused all the wrong modules to get loaded (including the io module).
I'm having the same problem. I installed python 2.7.11 via an installer from Python.org. Strangely, the issue seems to be related to some subtle difference between how OSX launches python when I invoke it from the shell using the full path vs. using just the word python.
So, for me, this works (invoking python via the full path /usr/local/bin/python):
$ which python
/usr/local/bin/python
$ /usr/local/bin/python -c "import io"
$
... but this doesn't:
$ python -c "import io"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
So, as a workaround, you can try doing the same thing.
Elsewhere, I've posted a separate question about this puzzling behavior. Maybe somehow merely calling python invokes some strange mix of the 2.7.11 executable with the 2.7.10 dylibs??
According to https://github.com/klen/python-mode/issues/634:
I had the same issue, but successfully fixed. In my case I compiled
python and vim with homebrew, when PYTHON_PATH has been specified and
set to one of my dev environments, where I also had some libraries,
including io. Workaround was simple: open new terminal, make sure that
you do not have custom PYTHON_PATH, uninstall python, uninstall vim.
Reinstall both of them.
and
Problem solved.
Culprit is the update from python 2.7.10 to 2.7.11.
If you are using conda package control, simply run "conda install
python=2.7.10" will solve this problem.
This doesn't give the root cause though. Since this happens with _io, this looks like a bug in python 2.7.11 (unlikely, there would be a world-scale outcry and a prompt fix if it was) or some packaging bug or version mismatch specifically with the homebrew version (and maybe some related ones, too).
Try to import _io in the console and if it succeeds, check if it was loaded from the same path.
Reinstall python.
brew unlink python && brew reinstall python
Secure the path
export PYTHONPATH=$PYTHONPATH:/usr/local/bin/
BACKUP and Change the order of "paths" file.
sudo nano /etc/paths
it seems, the order of paths, it is decisive to run python properly. In my case, the result was:
#sudo nano /etc/paths
/usr/bin
/usr/local/bin
/bin
/usr/sbin
/sbin
On my mac, path is like this.
$ which python
/usr/local/bin/python
Now I can run both:
$ /usr/local/bin/python -c "import io"
$ python -c "import io"
I had the same issue, it is successfully fixed by just replacing the _io.so file.
sudo find / -name _io.so
copy the path of the _io.so file which DOES NOT belong to python-2.7.11. For example, copy the path of _io.so which is under python-2.7.5:
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Replace the /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so file with the _io.so that you just found.
This happened to me as well in MacVim. I solved it by making sure :python print(sys.path) is using system Python (e.g. /Library/Python/2.7/...)
Since I installed MacVim via Homebrew, I just did that by:
Spawn a new shell that had which python -> /usr/bin/python. For my case I needed to remove the pyenv line from my .bash_profile. If you installed Python via Homebrew you may want to brew unlink python first
brew reinstall macvim
If your problem is caused by anaconda, it is unnecessary to remove //anaconda directory.
Just open your ~/.bash_profile, find the line
export PATH="//anaconda/bin:$PATH
and comment it out, then restart your terminal session.
Another quick workaround if you don't mind sticking with Python 2.7.10 is to specify the path of the Python interpreter executable that will be used for the virtualenv. On OSX that path is usually /usr/bin/python:
virtualenv venv --python=/usr/bin/python
Can't add comment (?) so this just to share my exp., downgrade to 2.7.10 works fr me.
I got this error after a failed NLTK download, I needed to uninstall anaconda:
sudo rm -rf ~/anaconda
update PATH variable
This happened when I already had tried to create a venv in a folder, and mistakenly was trying to initialize a second one! So I just removed venv directory and re-ran the command. Very likely this is not the answer to this solution, but searching my error brought me here, so it may help some others who are stuck.
I solved this issue by removing the symbolic link that was in /usr/local/bin and copying the actual python binary, that was pointed to by said link, there.
I had the same issue when I tried to use PyCharm. Solved by setting "python interpreter" in project configuration to point to the python virtual env I wanted to use, which was an Anaconda env. Somehow the interpreter path was missing the "anaconda" portion of ~/.../anaconda/.../_io.so. No need to uninstall anaconda.
there is surprisingly little documentation or tutorials about this.
I want to run pylearn2 on my Mac OSX 10.11.1.
Acoording to the tutorial I should run at first this line:
cd pylearn/pylearn2/scripts/tutorials/grbm_smd/
python make_dataset.py
Yet the script fails with this exception:
Traceback (most recent call last):
File "/Users/username/python/pylearn2/pylearn2/utils/string_utils.py", line 53, in preprocess
else os.environ[varname])
File "/Users/username/anaconda/lib/python3.4/os.py", line 633, in __getitem__
raise KeyError(key) from None
KeyError: 'PYLEARN2_DATA_PATH'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "make_dataset.py", line 27, in <module>
train = cifar10.CIFAR10(which_set="train")
File "/Users/username/python/pylearn2/pylearn2/datasets/cifar10.py", line 71, in __init__
string_utils.preprocess('${PYLEARN2_DATA_PATH}'),
File "/Users/username/python/pylearn2/pylearn2/utils/string_utils.py", line 56, in preprocess
reraise_as(NoDataPathError())
File "/Users/username/python/pylearn2/pylearn2/utils/exc.py", line 90, in reraise_as
six.reraise(type(new_exc), new_exc, orig_exc_traceback)
File "/Users/username/anaconda/lib/python3.4/site-packages/theano/compat/six.py", line 321, in reraise
raise value.with_traceback(tb)
File "/Users/username/python/pylearn2/pylearn2/utils/string_utils.py", line 53, in preprocess
else os.environ[varname])
File "/Users/username/anaconda/lib/python3.4/os.py", line 633, in __getitem__
raise KeyError(key) from None
pylearn2.utils.exc.NoDataPathError: You need to define your PYLEARN2_DATA_PATH environment variable. If you are
using a computer at LISA, this should be set to /data/lisa/data.
Platform-specific instructions for setting environment variables:
Linux
=====
On most linux setups, you can define your environment variable by adding this
line to your ~/.bashrc file:
export PYLEARN2_VIEWER_COMMAND="eog --new-instance"
*** YOU MUST INCLUDE THE WORD "export". DO NOT JUST ASSIGN TO THE ENVIRONMENT VARIABLE ***
If you do not include the word "export", the environment variable will be set
in your bash shell, but will not be visible to processes that you launch from
it, like the python interpreter.
Don't forget that changes from your .bashrc file won't apply until you run
source ~/.bashrc
or open a new terminal window. If you're seeing this from an ipython notebook
you'll need to restart the ipython notebook, or maybe modify os.environ from
an ipython cell.
Mac OS X
========
Environment variables on Mac OS X work the same as in Linux, except you should
modify and run the "source" command on ~/.profile rather than ~/.bashrc.
Original exception:
KeyError: PYLEARN2_DATA_PATH
I inserted the following information from the exception into ~/.profile
export PYLEARN2_VIEWER_COMMAND="eog --new-instance"
and ran
source ~/.bashrc
As it still threw an exception I did some research and found out I must put the .profile file into the .bash_profile. So I added this line to .bash_profile:
#.profile
source ~/.profile
However the outcome is still the same :(
Additional information
According to the installation guide says I should add another information to the path envoirement, yet I cannot understand which in particular.
hidden files in my system
.bash_history
.bash_profile
.bash_profile-anaconda.bak
.bash_sessions
.config
.ipython
.local
.profile
.python_history
.theano
.vminfo
After going through the code myself I've found the solution. There is a bug in the sourcecode, which is missing the download_cifar10.sh script. Plus the tutorial is missing a PATH variable which is necessary.
Instruction
1.) set the PATH variable
export PYLEARN2_VIEWER_COMMAND="eog --new-instance"
export PYLEARN2_DATA_PATH=/YOURPATHTOHERE/pylearn2/datasets
2.) download cifar-10 (python version)
3.) unpack it
You will get a "cifar-10-batches-py" folder
4.) Wrap "cifar-10-batches-py" in a "cifar-10" folder
5.) Put the "cifar-10" folder into /pylearn2/datasets
The final path containing the cifar-10 files should be:
../pylearn2/datasets/cifar-10-batches-py/cifar-10
You're ready to go!
The download script exist:
https://github.com/lisa-lab/pylearn2/blob/master/pylearn2/scripts/datasets/download_cifar10.sh
Did you download Pylearn2 correctly? Did you delete files in it by mistake?
Having trouble with virtualenv on Windows 7.
I run:
virtualenv _testenv
It returns:
Traceback (most recent call last):
File "C:\Python27\Scripts\virtualenv-script.py", line 9, in <module>
load_entry_point('virtualenv==1.5.2', 'console_scripts', 'virtualenv')()
File "C:\Python27\lib\site-packages\virtualenv.py", line 558, in main
prompt=options.prompt)
File "C:\Python27\lib\site-packages\virtualenv.py", line 647, in create_environment
site_packages=site_packages, clear=clear))
File "C:\Python27\lib\site-packages\virtualenv.py", line 771, in install_python
copy_required_modules(home_dir)
File "C:\Python27\lib\site-packages\virtualenv.py", line 725, in copy_required_modules
dst_filename = change_prefix(filename, dst_prefix)
File "C:\Python27\lib\site-packages\virtualenv.py", line 710, in change_prefix
(filename, prefixes)
AssertionError: Filename c:\Python27\Lib\os.py does not start with any of these prefixes: ['C:\\Python27']
I have the following environment variables:
PYTHONHOME=C:\Python27
PYTHONPATH=c:\Python27;c:\Python27\Lib
PYTHONSTARTUP=C:\Users\Larry\.pythonrc
PATH=%PYTHONHOME%\;%PYTHONHOME%\Scripts;etc
Installed ActiveState Python:
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win32
I updated the PYTHONPATH=C:\Python27;C:\Python27\Lib
Still looking for a solution, I found and removed AppData/Python*. Reinstalled Python and now have a different error:
C:\xbz>virtualenv _t
PYTHONHOME is set. You *must* activate the virtualenv before using it
Overwriting _t\Lib\site.py with new content
New python executable in _t\Scripts\python2.7.exe
Not overwriting existing python script _t\Scripts\python.exe (you must use _t\Scripts\python2.7.exe)
Overwriting _t\Lib\distutils\__init__.py with new content
Installing setuptools..............
Complete output from command C:\xbz\_t\Scripts\python2.7.exe -c "#!python
\"\"\"Bootstrap setuptoo...
" --always-copy -U setuptools:
Traceback (most recent call last):
File "<string>", line 278, in <module>
File "<string>", line 210, in main
File "<string>", line 132, in download_setuptools
File "C:\Python27\Lib\urllib2.py", line 94, in <module>
import httplib
File "C:\Python27\Lib\httplib.py", line 71, in <module>
import socket
File "C:\Python27\Lib\socket.py", line 47, in <module>
import _socket
ImportError: No module named _socket
----------------------------------------
...Installing setuptools...done.
Traceback (most recent call last):
File "C:\Python27\Scripts\virtualenv-script.py", line 9, in <module>
load_entry_point('virtualenv==1.5.2', 'console_scripts', 'virtualenv')()
File "C:\Python27\lib\site-packages\virtualenv.py", line 558, in main
prompt=options.prompt)
File "C:\Python27\lib\site-packages\virtualenv.py", line 654, in create_environment
install_setuptools(py_executable, unzip=unzip_setuptools)
File "C:\Python27\lib\site-packages\virtualenv.py", line 384, in install_setuptools
_install_req(py_executable, unzip)
File "C:\Python27\lib\site-packages\virtualenv.py", line 360, in _install_req
cwd=cwd)
File "C:\Python27\lib\site-packages\virtualenv.py", line 624, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command C:\xbz\_t\Scripts\python2.7.exe -c "#!python
\"\"\"Bootstrap setuptoo...
" --always-copy -U setuptools failed with error code 1
I hacked Lib/socket.py and inserted:
import sys
sys.path = ['', 'C:\\Python27\\lib\\site-packages\\dotcloud-0.3.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\dotcloud.cli-0.3.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\flask-0.7dev_20110622-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\werkzeug-0.6.2-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\gunicorn-0.12.2-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\wtforms-0.6.3-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\repoze.browserid-0.3-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\paste-1.7.5.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\django_pjax-1.0-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\paramiko-1.7.7.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pycrypto-2.4.1-py2.7-win32.egg', 'C:\\Python27', 'C:\\Python27\\Lib', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info', 'C:\\Python27\\Scripts', 'C:\\Python27\\Lib\\site-packages\\django\\bin']
Above
import _socket
The reason was that I was able to import socket from straight python prompt! So stuffed my existing path. I haven't narrowed down exactly which directory made it happy. It at least will reveal to someone else why I am getting the error without it.
Ideas? Suggestions?
Thank you. :)
I hacked Lib/socket.py and inserted:
import sys
sys.path.append('C:\\Python27\\DLLs')
Above
import _socket
3 year old question, but hopefully this answer can still help someone. Rather than setting the environment variables (which mysteriously didn't work for me), you can pass the path to your Python installation when setting up the virtual environment. In Windows, you have to path out to python.exe, but it seems that in Linux/OS X you just path to the folder. Examples:
Windows:
virtualenv -p <PATH TO PYTHON.EXE> venv
Linux/Mac:
virtualenv -p </user/path/to/python> venv
Both create a virtual environment in subfolder "venv" in current directory.
Try to set PYTHONPATH to PYTHONPATH=C:\Python27;C:\Python27\Lib (uppercase C at the start).
This can be done at the command prompt by typing set PYTHONPATH=C:\Python27;C:\Python27\Lib.
PYTHONPATH will revert back to whatever it previously was once that command prompt window is closed.
There is similar problem currently that shows error:
AssertionError: Filename C:\Python27\Lib\os.py does not start with any of
these prefixes: ['C:\\python27']
The difference is in 'C:\python27' being lower case. So the problem manifest itself in that you can not install new virtualenv or make a nested virtualenvs (we do it for testing sometimes).
The cause is in the conent of the PYTHONPATH
PYTHONPATH=C:\Python27;C:\Python27\Lib
For some reason sys.path in virtualenv.py will return c:\python27, but path to required modules will come form the PYTHONPATH and start with 'C:\Python27\Lib', hence the assertion error.
Long story short, just unset the PYTHONPATH.
For the _socket error, change your pythonpython path to:
PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs
You can try the following (supppose your python is in global path):
python -m virtualenv [foldername]
This works for me, Win 10, virtualenv 15.1.0
I get it from this video, it will excute the python lib instead of calling windows exe.
I have added
if is_win:
prefixes.append('C:\PYTHON27')
to virtualenv.py and it works.
Its strange but from the error message
AssertionError: Filename c:\Python27\Lib\os.py does not start with any of these prefixes: ['C:\\Python27']
It seems, it expects the path-name for the file os.py to start with upper case 'C' and the prefix sanity check is case sensitive.
As the path to the library is derived from PYTHONPATH and in your case the drive letter is in lower case, it seems logical to change it to upper case to resolve the issue.
like
PYTHONPATH=C:\Python27;C:\Python27\Lib
I hate "summary" answers, but as I just went through a very similar issue I thought I would post my solution here as well which draws from several of these answers.
The assert error was caused because I did not have a PYTHONPATH
environment variable setup.
The socket error was caused because I did not include the
PythonXX\DLLs folder.
The full PYTHONPATH environment variable should look follows:
PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs
This is an error already submitted to the Python development team: https://github.com/pypa/virtualenv/pull/697
In the meanwhile why not just change the Python installation folder name to (ptyhon27) to make the assertion work, or if you feel more confortable with that just reinstall python using the alternative location. It works with no issue.
I also ran into this problem on Windows 7. My Python27 installation was under C:\Program Files, which obviously contains a space in the path. So, on a separate Windows 7 system that did not contain Python, I did a fresh install of Python27 under C:\Python27 (the default installation path), followed by an install of setuptools (for easy_install).
Afterwards, I was able to install virtualenv CLEANLY without the above assertion error (I used easy_install).
I know that the OP's system is already using the default path, but I thought I would add my experience here as a possible solution for certain specific cases.
This issue is presumably a hangover from other more case-sensitive file systems.
Complete solution:
Read the error message from virtualenv. Remember the part where it says "does not start with any of these prefixes: ['C:\\Python27']".
Edit PYTHONPATH, or create it if you don't have one (Start+Break, Advanced system settings, Environment Variables). It shouldn't matter if it's a user variable or a system variable, unless you plan to switch user accounts.
Make the case match the error message. BOTH the drive letter AND the folder name must match (presumably intermediate folders as well, if you didn't install to C:\Python27). You can ignore the double backslash, one is fine.
The only change I made to fix the bug was as follows. The change should take effect for any new command / terminal sessions (close your open cmd.exe / powershell / etc. windows).
Old state: PYTHONPATH = C:\PYTHON27;C:\PYTHON27\LIB;C:\PYTHON27\DLLS
New state: PYTHONPATH = C:\Python27;C:\Python27\LIB;C:\Python27\DLLS
If you have any other items in your PYTHONPATH, you might as well change those too, but it probably won't affect virtualenv's ability to run.
Change "virtualenv.py" --> change_prefix with:
def change_prefix(filename, dst_prefix):
...
prefixes = sorted(prefixes, key=len, reverse=True)
filename = str(os.path.abspath(filename))[0].lower() + str(os.path.abspath(filename))[1:]
for src_prefix in prefixes:
if filename.startswith(src_prefix):
_, relpath = filename.split(src_prefix, 1)
if src_prefix != os.sep: # sys.prefix == "/"
assert relpath[0] == os.sep
relpath = relpath[1:]
return join(dst_prefix, relpath)
assert False, "Filename %s does not start with any of these prefixes: %s" % \
(filename, prefixes)
...
I had the same assertion error from a slightly different cause. The error was does not start with any of these prefixes: ['C:\\python27'] and note the lowercase "p". The actual folder names all use capital-P Python27. All the prefixes in PTYHONPATH were correct. However I had entered the PYTHONHOME variable as C:\python27 and although this was fine for Python, it caused the error in virtualenv.
Windows solution:
This is due to the difference between PYTHONPATH variable path and the one pipenv is expecting.
Suppose System Variable has below PYTHONPATH,
PYTHONPATH = C:\User\Bruce\AppData\Local\Programs\Python\Python37-32
And pipenv is looking for PYTHONPATH something like below:
PYTHONPATH = C:\users\bruce\appdata\local\programs\python\python37-32
Here, observe that the path text pipenv is looking has different case than what is set in System Environment variable.
To solve this issue try below steps by opening command prompt in folder where pipenv is to run:
> set PYTHONPATH=C:\users\bruce\appdata\local\programs\python\python37-32
You need to give exact same path that is shown in the AssertionError.
Then run below command to create pipenv
> pipenv install numpy
Any other library can be installed
after a computer fix my python projects dir (windows) changed (say from d: to f:).
now all my virtualenvs are broken. after activating the env the project inside the virtualenv can't find the dependencies and the custom scripts (from the env\scripts folder)won't work
tried running:
virtualenv --relocateble ENV_NAME (with the env name ..)
like in this stackoverflow question and it outputted a lot of lines like:
Script agent\Scripts\deactivate.bat cannot be made relative
and my virtualenv is still broken.
when I manually changed activate.bat set VIRTUAL_ENV to the new path. some scripts work again. but the relocate scripts still doesn't run and most of the scripts are still broken
even running the python interpeter fails with:
Traceback (most recent call last):
File "F:\Python27\learn\agent\agent\lib\site.py", line 677, in <module>
main()
File "F:\Python27\learn\agent\agent\lib\site.py", line 666, in main
aliasmbcs()
File "F:\Python27\learn\agent\agent\lib\site.py", line 506, in aliasmbcs
import locale, codecs
File "F:\Python27\learn\agent\agent\lib\locale.py", line 19, in <module>
import functools
ImportError: No module named functools
is there any way to fix this? HELP
Update: I also changed manually the shebang python interpeter line in all scripts in ENV\Scripts. now all fail with the same python failure as above
Another Update: to #udi the system python path is:
['', 'C:\\dev\\Python27\\lib\\site-packages\\distribute-0.6.37-py2.7.egg', 'C:\\
dev\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg', 'C:\\dev\\Python27\\lib
\\site-packages\\numpy-1.7.1-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\site-pac
kages\\pandas-0.11.0-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\site-packages\\p
ytz-2013b-py2.7.egg', 'C:\\dev\\Python27\\lib\\site-packages\\python_dateutil-2.
1-py2.7.egg', 'C:\\dev\\Python27\\lib\\site-packages\\six-1.3.0-py2.7.egg', 'C:\
\dev\\Python27\\lib\\site-packages\\tornado-3.0.1-py2.7.egg', 'C:\\dev\\Python27
\\lib\\site-packages\\pyzmq-13.1.0-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\si
te-packages\\pygments-1.6-py2.7.egg', 'C:\\Windows\\system32\\python27.zip', 'C:
\\dev\\Python27\\DLLs', 'C:\\dev\\Python27\\lib', 'C:\\dev\\Python27\\lib\\plat-
win', 'C:\\dev\\Python27\\lib\\lib-tk', 'C:\\dev\\Python27', 'C:\\dev\\Python27\
\lib\\site-packages', 'C:\\dev\\Python27\\lib\\site-packages\\setuptools-0.6c11-
py2.7.egg-info']
since I can't run python from the virtualenv, I can't print the python path from there
Correcting python directory path in ENV_FOLDER\Lib\orig-prefix.txt helped me
Seems like your system and local environments create a mix of libraries and binaries from different versions of python.
Chances are you would need to delete Lib, Scripts and Include and start again with virtualenv .. You might be able to save the site-packages folder, but if you have requirements.txt files, you should probably reinstall packages instead (see also: How do I install from a local cache with pip? ).
Anyway, I believe you can create a script that does all this in one step.
I installed both py2 and py3 on my windows 10. And got this error by create virtualenv by using virtualenv xxx directly. After purging folder xxx and reinstalling with virtualenv -p TARGET_PY_EXE xxx everything works smoothly.
Hope this will help multiple python windows users.
By the way, I simply create env variables as PY2 and PY3 instead of adding absolute paths into PATH.
Having trouble with virtualenv on Windows 7.
I run:
virtualenv _testenv
It returns:
Traceback (most recent call last):
File "C:\Python27\Scripts\virtualenv-script.py", line 9, in <module>
load_entry_point('virtualenv==1.5.2', 'console_scripts', 'virtualenv')()
File "C:\Python27\lib\site-packages\virtualenv.py", line 558, in main
prompt=options.prompt)
File "C:\Python27\lib\site-packages\virtualenv.py", line 647, in create_environment
site_packages=site_packages, clear=clear))
File "C:\Python27\lib\site-packages\virtualenv.py", line 771, in install_python
copy_required_modules(home_dir)
File "C:\Python27\lib\site-packages\virtualenv.py", line 725, in copy_required_modules
dst_filename = change_prefix(filename, dst_prefix)
File "C:\Python27\lib\site-packages\virtualenv.py", line 710, in change_prefix
(filename, prefixes)
AssertionError: Filename c:\Python27\Lib\os.py does not start with any of these prefixes: ['C:\\Python27']
I have the following environment variables:
PYTHONHOME=C:\Python27
PYTHONPATH=c:\Python27;c:\Python27\Lib
PYTHONSTARTUP=C:\Users\Larry\.pythonrc
PATH=%PYTHONHOME%\;%PYTHONHOME%\Scripts;etc
Installed ActiveState Python:
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win32
I updated the PYTHONPATH=C:\Python27;C:\Python27\Lib
Still looking for a solution, I found and removed AppData/Python*. Reinstalled Python and now have a different error:
C:\xbz>virtualenv _t
PYTHONHOME is set. You *must* activate the virtualenv before using it
Overwriting _t\Lib\site.py with new content
New python executable in _t\Scripts\python2.7.exe
Not overwriting existing python script _t\Scripts\python.exe (you must use _t\Scripts\python2.7.exe)
Overwriting _t\Lib\distutils\__init__.py with new content
Installing setuptools..............
Complete output from command C:\xbz\_t\Scripts\python2.7.exe -c "#!python
\"\"\"Bootstrap setuptoo...
" --always-copy -U setuptools:
Traceback (most recent call last):
File "<string>", line 278, in <module>
File "<string>", line 210, in main
File "<string>", line 132, in download_setuptools
File "C:\Python27\Lib\urllib2.py", line 94, in <module>
import httplib
File "C:\Python27\Lib\httplib.py", line 71, in <module>
import socket
File "C:\Python27\Lib\socket.py", line 47, in <module>
import _socket
ImportError: No module named _socket
----------------------------------------
...Installing setuptools...done.
Traceback (most recent call last):
File "C:\Python27\Scripts\virtualenv-script.py", line 9, in <module>
load_entry_point('virtualenv==1.5.2', 'console_scripts', 'virtualenv')()
File "C:\Python27\lib\site-packages\virtualenv.py", line 558, in main
prompt=options.prompt)
File "C:\Python27\lib\site-packages\virtualenv.py", line 654, in create_environment
install_setuptools(py_executable, unzip=unzip_setuptools)
File "C:\Python27\lib\site-packages\virtualenv.py", line 384, in install_setuptools
_install_req(py_executable, unzip)
File "C:\Python27\lib\site-packages\virtualenv.py", line 360, in _install_req
cwd=cwd)
File "C:\Python27\lib\site-packages\virtualenv.py", line 624, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command C:\xbz\_t\Scripts\python2.7.exe -c "#!python
\"\"\"Bootstrap setuptoo...
" --always-copy -U setuptools failed with error code 1
I hacked Lib/socket.py and inserted:
import sys
sys.path = ['', 'C:\\Python27\\lib\\site-packages\\dotcloud-0.3.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\dotcloud.cli-0.3.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\flask-0.7dev_20110622-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\werkzeug-0.6.2-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\gunicorn-0.12.2-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\wtforms-0.6.3-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\repoze.browserid-0.3-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\paste-1.7.5.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\django_pjax-1.0-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\paramiko-1.7.7.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pycrypto-2.4.1-py2.7-win32.egg', 'C:\\Python27', 'C:\\Python27\\Lib', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info', 'C:\\Python27\\Scripts', 'C:\\Python27\\Lib\\site-packages\\django\\bin']
Above
import _socket
The reason was that I was able to import socket from straight python prompt! So stuffed my existing path. I haven't narrowed down exactly which directory made it happy. It at least will reveal to someone else why I am getting the error without it.
Ideas? Suggestions?
Thank you. :)
I hacked Lib/socket.py and inserted:
import sys
sys.path.append('C:\\Python27\\DLLs')
Above
import _socket
3 year old question, but hopefully this answer can still help someone. Rather than setting the environment variables (which mysteriously didn't work for me), you can pass the path to your Python installation when setting up the virtual environment. In Windows, you have to path out to python.exe, but it seems that in Linux/OS X you just path to the folder. Examples:
Windows:
virtualenv -p <PATH TO PYTHON.EXE> venv
Linux/Mac:
virtualenv -p </user/path/to/python> venv
Both create a virtual environment in subfolder "venv" in current directory.
Try to set PYTHONPATH to PYTHONPATH=C:\Python27;C:\Python27\Lib (uppercase C at the start).
This can be done at the command prompt by typing set PYTHONPATH=C:\Python27;C:\Python27\Lib.
PYTHONPATH will revert back to whatever it previously was once that command prompt window is closed.
There is similar problem currently that shows error:
AssertionError: Filename C:\Python27\Lib\os.py does not start with any of
these prefixes: ['C:\\python27']
The difference is in 'C:\python27' being lower case. So the problem manifest itself in that you can not install new virtualenv or make a nested virtualenvs (we do it for testing sometimes).
The cause is in the conent of the PYTHONPATH
PYTHONPATH=C:\Python27;C:\Python27\Lib
For some reason sys.path in virtualenv.py will return c:\python27, but path to required modules will come form the PYTHONPATH and start with 'C:\Python27\Lib', hence the assertion error.
Long story short, just unset the PYTHONPATH.
For the _socket error, change your pythonpython path to:
PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs
You can try the following (supppose your python is in global path):
python -m virtualenv [foldername]
This works for me, Win 10, virtualenv 15.1.0
I get it from this video, it will excute the python lib instead of calling windows exe.
I have added
if is_win:
prefixes.append('C:\PYTHON27')
to virtualenv.py and it works.
Its strange but from the error message
AssertionError: Filename c:\Python27\Lib\os.py does not start with any of these prefixes: ['C:\\Python27']
It seems, it expects the path-name for the file os.py to start with upper case 'C' and the prefix sanity check is case sensitive.
As the path to the library is derived from PYTHONPATH and in your case the drive letter is in lower case, it seems logical to change it to upper case to resolve the issue.
like
PYTHONPATH=C:\Python27;C:\Python27\Lib
I hate "summary" answers, but as I just went through a very similar issue I thought I would post my solution here as well which draws from several of these answers.
The assert error was caused because I did not have a PYTHONPATH
environment variable setup.
The socket error was caused because I did not include the
PythonXX\DLLs folder.
The full PYTHONPATH environment variable should look follows:
PYTHONPATH=C:\Python27;C:\Python27\Lib;C:\Python27\DLLs
This is an error already submitted to the Python development team: https://github.com/pypa/virtualenv/pull/697
In the meanwhile why not just change the Python installation folder name to (ptyhon27) to make the assertion work, or if you feel more confortable with that just reinstall python using the alternative location. It works with no issue.
I also ran into this problem on Windows 7. My Python27 installation was under C:\Program Files, which obviously contains a space in the path. So, on a separate Windows 7 system that did not contain Python, I did a fresh install of Python27 under C:\Python27 (the default installation path), followed by an install of setuptools (for easy_install).
Afterwards, I was able to install virtualenv CLEANLY without the above assertion error (I used easy_install).
I know that the OP's system is already using the default path, but I thought I would add my experience here as a possible solution for certain specific cases.
This issue is presumably a hangover from other more case-sensitive file systems.
Complete solution:
Read the error message from virtualenv. Remember the part where it says "does not start with any of these prefixes: ['C:\\Python27']".
Edit PYTHONPATH, or create it if you don't have one (Start+Break, Advanced system settings, Environment Variables). It shouldn't matter if it's a user variable or a system variable, unless you plan to switch user accounts.
Make the case match the error message. BOTH the drive letter AND the folder name must match (presumably intermediate folders as well, if you didn't install to C:\Python27). You can ignore the double backslash, one is fine.
The only change I made to fix the bug was as follows. The change should take effect for any new command / terminal sessions (close your open cmd.exe / powershell / etc. windows).
Old state: PYTHONPATH = C:\PYTHON27;C:\PYTHON27\LIB;C:\PYTHON27\DLLS
New state: PYTHONPATH = C:\Python27;C:\Python27\LIB;C:\Python27\DLLS
If you have any other items in your PYTHONPATH, you might as well change those too, but it probably won't affect virtualenv's ability to run.
Change "virtualenv.py" --> change_prefix with:
def change_prefix(filename, dst_prefix):
...
prefixes = sorted(prefixes, key=len, reverse=True)
filename = str(os.path.abspath(filename))[0].lower() + str(os.path.abspath(filename))[1:]
for src_prefix in prefixes:
if filename.startswith(src_prefix):
_, relpath = filename.split(src_prefix, 1)
if src_prefix != os.sep: # sys.prefix == "/"
assert relpath[0] == os.sep
relpath = relpath[1:]
return join(dst_prefix, relpath)
assert False, "Filename %s does not start with any of these prefixes: %s" % \
(filename, prefixes)
...
I had the same assertion error from a slightly different cause. The error was does not start with any of these prefixes: ['C:\\python27'] and note the lowercase "p". The actual folder names all use capital-P Python27. All the prefixes in PTYHONPATH were correct. However I had entered the PYTHONHOME variable as C:\python27 and although this was fine for Python, it caused the error in virtualenv.
Windows solution:
This is due to the difference between PYTHONPATH variable path and the one pipenv is expecting.
Suppose System Variable has below PYTHONPATH,
PYTHONPATH = C:\User\Bruce\AppData\Local\Programs\Python\Python37-32
And pipenv is looking for PYTHONPATH something like below:
PYTHONPATH = C:\users\bruce\appdata\local\programs\python\python37-32
Here, observe that the path text pipenv is looking has different case than what is set in System Environment variable.
To solve this issue try below steps by opening command prompt in folder where pipenv is to run:
> set PYTHONPATH=C:\users\bruce\appdata\local\programs\python\python37-32
You need to give exact same path that is shown in the AssertionError.
Then run below command to create pipenv
> pipenv install numpy
Any other library can be installed