[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-09 Thread Chris Caron

New submission from Chris Caron :

The Windows install of Python 2.7.13 defaults it's install into 
**C:\Python27**.  It creates several subdirectories within this; one of which 
is **C:\Python27\lib\site-packages\backports**. So just out of the box (without 
this script installed):
```python
import backports
print(backports.__path__)
# C:\Python27\lib\site-packages\backports
```

I have a custom package that sets the sys.path(0, "new path") entry which works 
great in Linux. I ship all my modules and settings in this path.  This to work 
great in Windows too 'except' for the reference to `backports`.

Consider the block of code:
```python
import sys
from os import getcwd
from os.path import join
sys.path.insert(0, join(getcwd(), 'MyLibraries'))

# Now if we import backports, we should find the one in our MyLibraries 
directory
import backports
print(backports.__path__)# Nope... :(
# C:\Python27\lib\site-packages\backports

# What's weird is it's not entirely broken... you can do the following:
import chardet
print(chardet.__path__)
# Prints my path to MyLibraries/chardet
# So the path is correct and other libraries are coming in correctly
```

What's really weird, is (in Windows) even if i delete the 
**C:\Python27\lib\site-packages\backports**, it still imports the module; so 
it's like part of the Python27 build in some way.

`pip install` with the backports module I want works great because it drops the 
correct package in this 'lib/site-packages\backports' directory which is 
constantly being referenced.

>From what I can see the Microsoft version of Python27 can't seem to stop 
>referencing (even when told not to) the _backports_ location. Linux works 
>perfectly (as intended) but having customers port to this isn't an option for 
>me.

--
components: Windows
messages: 304001
nosy: Chris Caron, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: backports import path can not be overridden in Windows (Linux works fine)
type: behavior
versions: Python 2.7

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-09 Thread Chris Caron

Chris Caron  added the comment:

Thank you for replying so quickly;  the issue stems from a bug created here
which explains it a bit better:
https://github.com/caronc/nzb-notify/issues/27 (scroll to the bottom).

In my case, I had a lib\site-packages\backports in C:\Python27 that keeps
over-riding the one defined in the \MyLibraries path. But even when the
'sys.path' has been successfully overridden, the backports module (one i
provide for the package of interest) keeps reverting to the
C:\Python27\lib\site-packages\ path.  It actually just throws an exception
that the module doesn't exist (when ordering of paths would say it does).

To answer your other question: I got the installer from here:
https://www.python.org/downloads/release/python-2713/ (the MSI 64 bit
installer - second from the bottom)

--

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-10 Thread Chris Caron

Change by Chris Caron :


Added file: https://bugs.python.org/file47205/Test.py

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-10 Thread Chris Caron

Change by Chris Caron :


Added file: https://bugs.python.org/file47206/site-packages-Directory.png

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-10 Thread Chris Caron

Change by Chris Caron :


Added file: https://bugs.python.org/file47207/Test.Directory.png

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-10 Thread Chris Caron

Change by Chris Caron :


Added file: https://bugs.python.org/file47208/Test.Script.Backports.Dir.png

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-10 Thread Chris Caron

Change by Chris Caron :


Added file: https://bugs.python.org/file47209/Test.Script.Output.png

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-10 Thread Chris Caron

Change by Chris Caron :


Added file: https://bugs.python.org/file47210/Python.Test.zip

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-10 Thread Chris Caron

Chris Caron  added the comment:

I'm not doing anything unusual.

Just to recap, I installed Python27 (in Windows 7 in my case- but this problem 
happens in Windows 10 too).

I did use `pip` to install packages as you'll see in the screenshot.  But even 
if i rename the `C:\Python27\Lib\site-packages\backports` to 
`ignoreme-backports`.  When i change the PYTHONPATH (from within 
sys.path.insert(0, 'new_path/that/has/a/backports/dir/in/it');

import backports
print backports.__path__
# always prints: C:\Python27\Lib\site-packages\backports

The problem arises because the following code won't work in my program:

from import import ssl_match_hostname

^^ That throws an exception that the package doesn't exist.  It's debugging it 
to the __path__ being incorrect that caused me to create this ticket.

--

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-11 Thread Chris Caron

Chris Caron  added the comment:

-- Download Instructions
* 64 Bit ver of Python v2.7 for Windows 
https://www.python.org/ftp/python/2.7/python-2.7.amd64.msi
* Microsoft Visual C++ Compiler for Python 2.7: 
https://www.microsoft.com/en-ca/download/details.aspx?id=44266. 

-- Installation Instructions
* Install Python v2.7 (run python-2.7.amd64.msi); choose default options. 
Note: In my case, i uninstalled my already installed version (for the purpose 
of this post) first and made sure to delete the C:\Python27 directory left 
behind). Then I reinstalled the package.
   Default Options:
  - Install for all users
  - Install location: C:\Python27\
  - All packages installed (5 of 5 subfeatures)
  
** Heads up
So at this point, the C:\Python27\Lib\site-packages will contain the following: 
pip, setuptools,  and wheel.

-- A Starting Point
* Download the Python.Test.zip file i attached, but since you made it clear you 
want everything to be present in this message, i'll do my best to try to 
document it and paste content here: 
It's main contents is just to provide an alternative include directory called 
Test. In this test directory i provide six.py, odereddict, chardet, backports, 
socks and sockhandler.
>>>>> dir listing of Test
10/11/2017  06:04 PM  .
10/11/2017  06:04 PM  ..
10/11/2017  06:04 PM  backports
10/11/2017  06:04 PM  chardet
10/11/2017  06:04 PM 4,221 ordereddict.py
10/11/2017  06:04 PM 4,916 ordereddict.pyc
10/11/2017  06:04 PM23,462 six.py
10/11/2017  06:04 PM23,754 six.pyc
10/11/2017  06:04 PM32,006 socks.py
10/11/2017  06:04 PM 2,913 sockshandler.py
10/11/2017  06:04 PM 0 __init__.py
   7 File(s) 91,272 bytes
>>>>> End DIR Listing

Now lets introduce the second part of the zip file i provided. Test.py.  It's 
sitting next to (not in) the Test directory i listed above. It looks like this
>>>>> Test.py
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import sys
from os.path import join
from os.path import abspath
from os.path import dirname

print('Path Before Change: {0}'.format('\n'.join(sys.path)))
sys.path.insert(0, join(dirname(abspath(__file__)), 'Test'))
print('Path After Change: {0}'.format('\n'.join(sys.path)))

import backports
print('Backports Path: {0}'.format(backports.__path__))

import chardet
print('chardet Path: {0}'.format(chardet.__path__))

import six
print('six Path: {0}'.format(six.__file__))
>>>>> end Test.py

Those who already downloaded Test.py will notice i stripped out all of the 
comments.  Bear with me here, the actual code lines are still all unchanged.
I also placed the attached zip file into my root C:\ directory.  Not ideal for 
obvious reasons, but for this test, it makes the output small and easy to 
follow.

-- Script Run # 1
When i run the above script... right now... i get:
>>>>>
C:\Python.Test>python Test.py
Path Before Change: C:\Python.Test
C:\windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
Path Before Change: C:\Python.Test\Test
C:\Python.Test
C:\windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
Backports Path: ['C:\\Python.Test\\Test\\backports']
chardet Path: ['C:\\Python.Test\\Test\\chardet']
six Path: C:\Python.Test\Test\six.pyc
>>>>>

Like you said... everything is fine; it's not a python issue... but hang on...

Let's use pip and install some simple packages...
>>>>>
C:\Python.Test>pip install pylint
... lots of content flies by; but it's successful
>>>>>

Let's run our script again (same one... same content). If you're doing this 
from the command line, then cut and paste:
>>>>>
C:\Python.Test>python Test.py
Path Before Change: C:\Python.Test
C:\windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
Path Before Change: C:\Python.Test\Test
C:\Python.Test
C:\windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
Backports Path: ['C:\\Python27\\lib\\site-packages\\backports']
chardet Path: ['C:\\Python.Test\\Test\\chardet']
six Path: C:\Python.Test\Test\six.pyc
>>>>>

So... what should you take from this?
- backports is no longer referencing the one the PYTHONPATH (well 
sys.path.insert()) suggested otherwise.
- but we know it works because the other entries were

[issue31741] backports import path can not be overridden in Windows (Linux works fine)

2017-10-11 Thread Chris Caron

Chris Caron  added the comment:

Just to point out, i forgot the instructions of installing pip (right before) 
the following entry in my last post:
>> ** Heads up
>> So at this point, the C:\Python27\Lib\site-packages will contain the >>> 
>> following: pip, setuptools,  and wheel.

To be thorough, i should add that that i followed these instruction: 
https://pip.pypa.io/en/stable/installing/

Which required me to download get-pip.py from here 
https://bootstrap.pypa.io/get-pip.py and run it.  The rest of the instructions 
(after the **heads up) comment are still all on note.

--

___
Python tracker 
<https://bugs.python.org/issue31741>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com