Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overcome - pip install ansible on windows failing with filename or extension too long on windows

how to fix the pip install failures on windows with below error. Getting this error while trying to install ansible.

I suspect it is with issue with selected pip package for install. but the same is working fine with Linux based systems. Will there be any difference with OS for pip install

Exception:
Traceback (most recent call last):
  File "c:\python27\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\python27\lib\site-packages\pip\commands\install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "c:\python27\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "c:\python27\lib\site-packages\pip\req\req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "c:\python27\lib\site-packages\pip\download.py", line 821, in unpack_url
    hashes=hashes
  File "c:\python27\lib\site-packages\pip\download.py", line 663, in unpack_http_url
    unpack_file(from_path, location, content_type, link)
  File "c:\python27\lib\site-packages\pip\utils\__init__.py", line 605, in unpack_file
    untar_file(filename, location)
  File "c:\python27\lib\site-packages\pip\utils\__init__.py", line 553, in untar_file
    ensure_dir(path)
  File "c:\python27\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "C:\Python27\Lib\os.py", line 157, in makedirs
    mkdir(name, mode)
WindowsError: [Error 206] The filename or extension is too long: 'c:\\users\\user123\\appdata\\local\\temp\\pip-build-isnb2t\\ansible\\test/integration/targets/copy/files/subdir/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/'
like image 775
ac184 Avatar asked Feb 08 '18 20:02

ac184


People also ask

What happens if pip install doesn't work?

Reinstall Python to Fix 'Pip' is Not Recognized as an Internal or External Command. This error usually means there's a problem with the Python installation or the system variable PATH is not set up correctly. Try reinstalling Python and all its components to fix the problem.

How do I speed up pip install?

Going (very slightly) faster by disabling the version check On startup pip may check if you're running the latest version or not, and print a warning if you're not. You can disable this check like so: pip --disable-pip-version-check install ...

Why pip Cannot install package?

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you're trying to run in your current directory. In most cases, you'll need to navigate to the directory in which the tool is installed before you can run the command to launch it.


2 Answers

Well, it seems to be a known bug:

https://github.com/ansible/ansible/issues/31419

In Ansible 2.4.0, the module copy use symbolic links in the tests suite: https://github.com/ansible/ansible/tree/devel/test/integration/targets/copy/files/subdir/subdir1

circles -> ../
subdir3 -> ../subdir2/subdir3

Windows 10, cannot create this directories tree because the path is too long. In fact the resolved path is:

test/integration/targets/copy/files/subdir/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir1/circles/subdir2/subdir3/

bug report ends with:

We do not support installing ansible directly on a windows machine. You will need a linux like operating system to install ansible on

Workaround

A possible workaround is to download the wheel on pypi, it doesn't depend on Linux or whatever, probably pure python:

https://pypi.python.org/pypi/ansible/2.5.0a

(the pip install ansible command downloads the "source" .tgz archive, performs tests, ... and the path issue is within the tests, so let's use a ready-to-use pre-built bundle)

Once downloaded, use pip install path/to/the/wheel/file.whl

Tested and installed successfully on my Windows 10 machine:

C:\Users\jotd>c:\Python27\Scripts\pip install C:\Users\jotd\Downloads\ansible-2.5.0a1-py2-none-any.whl
Processing c:\users\jotd\downloads\ansible-2.5.0a1-py2-none-any.whl
Requirement already satisfied: PyYAML in c:\python27\lib\site-packages (from ansible==2.5.0a1)
Collecting cryptography (from ansible==2.5.0a1)
<a lot of package collecting...>
Installing collected packages: idna, pycparser, cffi, asn1crypto, ipaddress, cryptography, pynacl, bcrypt, pyasn1, paramiko, ansible
  Running setup.py install for pycparser ... done
  Running setup.py install for ipaddress ... done
Successfully installed ansible-2.5.0a1 asn1crypto-0.24.0 bcrypt-3.1.4 cffi-1.11.4 cryptography-2.1.4 idna-2.6 ipaddress-1.0.19 paramiko-2.4.0 pyasn1-0.4.2 pycparser-2.18 pynacl-1.2.1

ok, installed, but let's try to import it:

C:\Users\jotd>c:\python27\python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansible
>>>

works! yay!

like image 61
Jean-François Fabre Avatar answered Oct 12 '22 01:10

Jean-François Fabre


I got ansible installed without using pip, which seemed pretty straight forward to me.

Steps:

  • download compressed .tgz archive from https://pypi.org/project/ansible/

  • open 7-zip with right-click run as administrator and extract. <- admin is necessary because of symbolic links

  • opened an admin console in the folder and ran:

    python setup.py install

now ansible is installed on Windows.

like image 30
rosmcmahon Avatar answered Oct 12 '22 00:10

rosmcmahon