Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rez-pip not working ? #904

Closed
zclongpop123 opened this issue Jul 14, 2020 · 4 comments · Fixed by #1157
Closed

rez-pip not working ? #904

zclongpop123 opened this issue Jul 14, 2020 · 4 comments · Fixed by #1157

Comments

@zclongpop123
Copy link
Contributor

I used rez-pip -i xlrd to install packages, but it not working, It working well on 2.58.1

10:20:33 INFO Trying to use pip from python package
Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 174, in _run_module_as_main
"main", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in run_code
exec code in run_globals
File "C:\rez\2.61.1\Scripts\rez\rez-pip.exe_main
.py", line 7, in
File "c:\rez\2.61.1\lib\site-packages\rez\cli_entry_points.py", line 187, in run_rez_pip
return run("pip")
File "c:\rez\2.61.1\lib\site-packages\rez\cli_main.py", line 160, in run
returncode = run_cmd()
File "c:\rez\2.61.1\lib\site-packages\rez\cli_main.py", line 152, in run_cmd
return func(opts, opts.parser, extra_arg_groups)
File "c:\rez\2.61.1\lib\site-packages\rez\cli\pip.py", line 76, in command
extra_args=opts.extra)
File "c:\rez\2.61.1\lib\site-packages\rez\pip.py", line 261, in pip_install_package
py_exe, context = find_pip(pip_version, python_version)
File "c:\rez\2.61.1\lib\site-packages\rez\pip.py", line 95, in find_pip
python_version, pip_version=version
File "c:\rez\2.61.1\lib\site-packages\rez\pip.py", line 212, in find_pip_from_context
text=True
File "c:\rez\2.61.1\lib\site-packages\rez\resolved_context.py", line 920, in _check
return fn(self, *nargs, **kwargs)
File "c:\rez\2.61.1\lib\site-packages\rez\resolved_context.py", line 1172, in execute_command
return interpreter.subprocess(args, **Popen_args)
File "c:\rez\2.61.1\lib\site-packages\rez\rex.py", line 658, in subprocess
**subproc_kwargs)
File "c:\rez\2.61.1\lib\site-packages\rez\utils\execution.py", line 79, in init
super(Popen, self).init(args, **kwargs)
File "C:\Python27\Lib\subprocess.py", line 394, in init
errread, errwrite)
File "C:\Python27\Lib\subprocess.py", line 599, in _execute_child
args = list2cmdline(args)
File "C:\Python27\Lib\subprocess.py", line 266, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'NoneType' is not iterable

@Soulayrol
Copy link

Hello,
I have the same problem. I found why :
When I have installed rez, I use the

rez-bind --quickstart -i "C:/packages/default"

This command creates basic package including python package.
If you look inside this package (into the bin folder) you see a .symlink for the python executable.

The error is due to this symlink and rez pip search for a real python.exe.
So the easy fix is to replace the symlink by a copy of python.exe

For the devs, I don't wanna change your code but the problem come from : REZ_INSTALL\Lib\site-packages\rez\pip.py
ligne: 124 (find_python_in_context) the problem is this can't find python simlink

Hope it's help

@zclongpop123
Copy link
Contributor Author

thank you, I find another way to fix this...

After install rez and bind rez default packages, download a web enabled python version from python web side, put it into python package same folder, change a little of package,py, and it worked...

@ColinKennedy
Copy link

ColinKennedy commented Jan 24, 2021

Hi, this is still an issue in Rez 2.72.0 for Windows. The problem is that rez.backport.shutilwhich.which does not work on Windows. I haven't checked my fix works in Linux yet but I replaced that module/function with whichcraft and it worked almost immediately on Windows. whichcraft.which doesn't have a env parameter so I added it manually, like this

# -*- coding: utf-8 -*-

__author__ = "Daniel Roy Greenfeld"
__email__ = "pydanny@gmail.com"
__version__ = "0.6.1"

import os
import sys

try:  # Forced testing
    from shutil import which
except ImportError:  # Forced testing
    # Versions prior to Python 3.3 don't have shutil.which

    def which(cmd, mode=os.F_OK | os.X_OK, path=None, env=None):
        """Given a command, mode, and a PATH string, return the path which
        conforms to the given mode on the PATH, or None if there is no such
        file.
        `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
        of os.environ.get("PATH"), or can be overridden with a custom search
        path.
        Note: This function was backported from the Python 3 source code.
        """
        # Check that a given file can be accessed with the correct mode.
        # Additionally check that `file` is not a directory, as on Windows
        # directories pass the os.access check.

        def _access_check(fn, mode):
            return os.path.exists(fn) and os.access(fn, mode) and not os.path.isdir(fn)

        # If we're given a path with a directory part, look it up directly
        # rather than referring to PATH directories. This includes checking
        # relative to the current directory, e.g. ./script
        if os.path.dirname(cmd):
            if _access_check(cmd, mode):
                return cmd

            return None

        if env is None:
            env = os.environ

        if path is None:
            path = env.get("PATH", os.defpath)
        if not path:
            return None

        path = path.split(os.pathsep)

        if sys.platform == "win32":
            # The current directory takes precedence on Windows.
            if os.curdir not in path:
                path.insert(0, os.curdir)

            # PATHEXT is necessary to check on Windows.
            pathext = env.get("PATHEXT", "").split(os.pathsep)
            # See if the given file matches any of the expected path
            # extensions. This will allow us to short circuit when given
            # "python.exe". If it does match, only test that one, otherwise we
            # have to try others.
            if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
                files = [cmd]
            else:
                files = [cmd + ext for ext in pathext]
        else:
            # On other platforms you don't have things like PATHEXT to tell you
            # what file suffixes are executable, so just pass on cmd as-is.
            files = [cmd]

        seen = set()
        for dir in path:
            normdir = os.path.normcase(dir)
            if normdir not in seen:
                seen.add(normdir)
                for thefile in files:
                    name = os.path.join(dir, thefile)
                    if _access_check(name, mode):
                        return name

        return None

@nerdvegas do you mind if I make a PR with this change, assuming tests pass on Linux?

@manuelkoester
Copy link

This is still an issue on Windows with Python 3.9.7.

I've tweaked my local rez with similar changes of @ColinKennedy 's proposal.

Here's the correct link to whichcraft.
I hope it's okay if I pick it up from here and do a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants