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

ERROR: Could not find an activated virtualenv (required). #777

Closed
mhsmith opened this issue Jan 25, 2023 · 4 comments
Closed

ERROR: Could not find an activated virtualenv (required). #777

mhsmith opened this issue Jan 25, 2023 · 4 comments
Labels
Milestone

Comments

@mhsmith
Copy link
Member

mhsmith commented Jan 25, 2023

From beeware/toga#1747, with Chaquopy 14.0.0:

Date/Time:       2023-01-20 08:51:43 
Command line:    /Users/rkm/beeware/toga/venv3.10/bin/briefcase run android --test -d @beePhone

OS Release:      Darwin 21.6.0
OS Version:      Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000
Architecture:    arm64
Platform:        macOS-12.5.1-arm64-arm-64bit

Python exe:      /Users/rkm/beeware/toga/venv3.10/bin/python3.10
Python version:  3.10.9 (v3.10.9:1dd9be6584, Dec  6 2022, 14:37:36) [Clang 13.0.0 (clang-1300.0.29.30)]
Virtual env:     True
Conda env:       False

Briefcase:       0.3.12.dev305+g40fccb13
Target platform: android
Target format:   gradle

Environment Variables:
    COLORTERM=truecolor
    COMMAND_MODE=unix2003
    DIRENV_DIFF=eJx00E2TmjAAgOH_krMUkkBImOkhQmRZRFY-iu2F4SOsaxB3QV2s43_v9NDZU-_Pe3nv4B0498cCDMC5Ay9IxOZH6QUJcICm55McJ31UR72W8rMapX4-vVZg8c-tgrUADviP07_J4To2X7zgmfskUuAA-TxPvycYzh7f8niJj7uXXyRNsyszmdub9O1n-x7jYo22hmrSS2DfTNnv0PKglb1rETUg4Xa-Vfmsxi4lH3uYrXZnU2T4g8Ft7kt3HvGNhsJWOQpwMXMhX65d4Rs31l0OuOHUturnYB5qbdVKRq6Fr4bIiiLony97lwqxibKoHrUtIiiNDlN8PEHmDStYvX7uE9S_MUOFherZkWqdiusQPsVDR7p84Nwry9JfJm30HSzAmi_FOi2zOBQb4ABs2QZEpGFVY7ekYbS2MGMUGha0OmpULaKImJB8lXkqkg2P_o7uRlmp-nTDtonA4_EnAAD__1gyh3I=
    DIRENV_DIR=-/Users/rkm/beeware/toga
    DIRENV_FILE=/Users/rkm/beeware/toga/.envrc
    DIRENV_WATCHES=eJxszs1KxDAQAOB3mXPZ6SSTv949Cl48iYdpO3WL2Q0kcSuI7y4elX2Bj-_lC56kn2ECfG5aG9b3C86qh1TFXt4ET3q91QUGeCxr3y8KE7kU2I3WxAEePvfWG0y9fuj3cA875bJIxnb-Fde96vWGknM5MM1GtuhC8EENMTMbr-Q262SMjsOmo19DnF1agwhR2li90kKWkl9m8-fkObK1HOnf6fUnAAD___GBRdM=
    GIT_ASKPASS=********************
    HOME=/Users/rkm
    HOMEBREW_CELLAR=/opt/homebrew/Cellar
    HOMEBREW_PREFIX=/opt/homebrew
    HOMEBREW_REPOSITORY=/opt/homebrew
    INFOPATH=/opt/homebrew/share/info:
    LABELS_TOKEN=********************
    LABELS_USERNAME=freakboy3742
    LANG=en_GB.UTF-8
    LOGNAME=rkm
    MANPATH=/Users/rkm/.nvm/versions/node/v16.14.2/share/man:/opt/homebrew/share/man::
    MallocNanoZone=0
    NVM_BIN=/Users/rkm/.nvm/versions/node/v16.14.2/bin
    NVM_CD_FLAGS=-q
    NVM_DIR=/Users/rkm/.nvm
    NVM_INC=/Users/rkm/.nvm/versions/node/v16.14.2/include/node
    OLDPWD=/Users/rkm/beeware/toga
    ORIGINAL_XDG_CURRENT_DESKTOP=undefined
    PATH=/Users/rkm/beeware/toga/venv3.10/bin:/Users/rkm/.nvm/versions/node/v16.14.2/bin:/Users/rkm/.rbenv/shims:/Library/Frameworks/Python.framework/Versions/3.11/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/rkm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/rkm/.local/bin:/Users/rkm/.local/bin
    PIP_REQUIRE_VIRTUALENV=true
    PIP_RESPECT_VIRTUALENV=true
    PROMPT=%m:%1~ %# 
    PS1=(venv3.10) %n@%m %1~ %# 
    PWD=/Users/rkm/beeware/toga/testbed
    RBENV_SHELL=zsh
    SHELL=/bin/zsh
    SHLVL=1
    SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.M5P5N7p6Wc/Listeners
    TERM=xterm-256color
    TERM_PROGRAM=vscode
    TERM_PROGRAM_VERSION=1.74.3
    TMPDIR=/var/folders/b_/khqk71xd45d049kxc_59ltp80000gn/T/
    USER=rkm
    USER_ZDOTDIR=/Users/rkm
    VIRTUAL_ENV=/Users/rkm/beeware/toga/venv3.10
    VIRTUAL_ENV_PROMPT=(venv3.10) 
    VSCODE_GIT_ASKPASS_EXTRA_ARGS=********************
    VSCODE_GIT_ASKPASS_MAIN=********************
    VSCODE_GIT_ASKPASS_NODE=********************
    VSCODE_GIT_IPC_HANDLE=/var/folders/b_/khqk71xd45d049kxc_59ltp80000gn/T/vscode-git-aefd22eb56.sock
    VSCODE_INJECTION=1
    XPC_FLAGS=0x0
    XPC_SERVICE_NAME=0
    ZDOTDIR=/Users/rkm
    _=/Users/rkm/beeware/toga/venv3.10/bin/briefcase
    __CFBundleIdentifier=com.microsoft.VSCode
    __CF_USER_TEXT_ENCODING=0x1F5:0x0:0xF

Briefcase Log:
[08:51:35]                                                                                                                                                         subprocess.py:659
           >>> Running Command:                                                                                                                                    subprocess.py:660
           >>>     arch -x86_64 true                                                                                                                               subprocess.py:661
           >>> Working Directory:                                                                                                                                  subprocess.py:668
           >>>     /Users/rkm/beeware/toga/testbed                                                                                                                 subprocess.py:669
           >>> Return code: 0                                                                                                                                      subprocess.py:696
                                                                                                                                                                   subprocess.py:659
           >>> Running Command:                                                                                                                                    subprocess.py:660
           >>>     /usr/libexec/java_home                                                                                                                          subprocess.py:661
           >>> Working Directory:                                                                                                                                  subprocess.py:668
           >>>     /Users/rkm/beeware/toga/testbed                                                                                                                 subprocess.py:669
           >>> Command Output:                                                                                                                                     subprocess.py:685
           >>>     The operation couldn’t be completed. Unable to locate a Java Runtime.                                                                           subprocess.py:687
           >>>     Please visit http://www.java.com for information on installing Java.                                                                            subprocess.py:687
           >>>                                                                                                                                                     subprocess.py:687
           >>> Return code: 1                                                                                                                                      subprocess.py:696
           >>> Android emulator is already installed.                                                                                                             android_sdk.py:426
                                                                                                                                                                       create.py:788
           [testbed] Generating application template...                                                                                                                create.py:788
           Using app template: https://github.com/beeware/briefcase-android-gradle-template, branch chaquopy-14.0.0                                                    create.py:285
[08:51:36] Using existing template (sha ae6530b8dbcc6bcdb6a15d64f98520efb91116b7, updated Thu Jan 19 13:23:29 2023)                                                      base.py:776
                                                                                                                                                                       create.py:791
           [testbed] Installing support package...                                                                                                                     create.py:791
           No support package required.                                                                                                                                create.py:337
                                                                                                                                                                       create.py:798
           [testbed] Installing application code...                                                                                                                    create.py:798
           Installing src/testbed... done                                                                                                                              create.py:579
           Installing tests... done                                                                                                                                    create.py:579
           Installing ../android/tests_backend... done                                                                                                                 create.py:579
                                                                                                                                                                       create.py:801
           [testbed] Installing requirements...                                                                                                                        create.py:801
           Writing requirements file... done                                                                                                                           create.py:432
                                                                                                                                                                       create.py:804
           [testbed] Installing application resources...                                                                                                               create.py:804
           Installing src/testbed/resources/testbed-round-48.png as 48px round application icon... done                                                                create.py:660
           Installing src/testbed/resources/testbed-round-72.png as 72px round application icon... done                                                                create.py:660
           Installing src/testbed/resources/testbed-round-96.png as 96px round application icon... done                                                                create.py:660
           Installing src/testbed/resources/testbed-round-144.png as 144px round application icon... done                                                              create.py:660
           Installing src/testbed/resources/testbed-round-192.png as 192px round application icon... done                                                              create.py:660
           Installing src/testbed/resources/testbed-square-48.png as 48px square application icon... done                                                              create.py:660
           Installing src/testbed/resources/testbed-square-72.png as 72px square application icon... done                                                              create.py:660
           Installing src/testbed/resources/testbed-square-96.png as 96px square application icon... done                                                              create.py:660
           Installing src/testbed/resources/testbed-square-144.png as 144px square application icon... done                                                            create.py:660
           Installing src/testbed/resources/testbed-square-192.png as 192px square application icon... done                                                            create.py:660
                                                                                                                                                                       create.py:807
           [testbed] Removing unneeded app content...                                                                                                                  create.py:807
           No app content clean up required.                                                                                                                           create.py:763
                                                                                                                                                                       create.py:810
           [testbed] Created android/gradle/Toga Testbed                                                                                                               create.py:810
                                                                                                                                                                       gradle.py:219
           [testbed] Updating app metadata...                                                                                                                          gradle.py:219
           Setting main module... done                                                                                                                                 gradle.py:201
                                                                                                                                                                       gradle.py:222
           [testbed] Building Android APK...                                                                                                                           gradle.py:222
           >>> Android emulator is already installed.                                                                                                             android_sdk.py:426
                                                                                                                                                                   subprocess.py:659
           >>> Running Command:                                                                                                                                    subprocess.py:660
           >>>     '/Users/rkm/beeware/toga/testbed/android/gradle/Toga Testbed/gradlew' assembleDebug --console plain                                             subprocess.py:661
           >>> Working Directory:                                                                                                                                  subprocess.py:668
           >>>     /Users/rkm/beeware/toga/testbed/android/gradle/Toga Testbed                                                                                     subprocess.py:669
           >>> Environment Overrides:                                                                                                                              subprocess.py:678
           >>>     ANDROID_SDK_ROOT=/Users/rkm/Library/Caches/org.beeware.briefcase/tools/android_sdk                                                              subprocess.py:680
           >>>     JAVA_HOME=/Users/rkm/Library/Caches/org.beeware.briefcase/tools/java/Contents/Home                                                              subprocess.py:680
[08:51:39]                                                                                                                                                         subprocess.py:633
           > Configure project :app                                                                                                                                subprocess.py:633
           Warning: Python version 3.10 may have fewer packages available. If you experience problems, try switching to version 3.8.                               subprocess.py:633
                                                                                                                                                                   subprocess.py:633
           > Task :app:preBuild UP-TO-DATE                                                                                                                         subprocess.py:633
           > Task :app:preDebugBuild UP-TO-DATE                                                                                                                    subprocess.py:633
           > Task :app:compileDebugAidl NO-SOURCE                                                                                                                  subprocess.py:633
           > Task :app:compileDebugRenderscript NO-SOURCE                                                                                                          subprocess.py:633
           > Task :app:generateDebugBuildConfig                                                                                                                    subprocess.py:633
           > Task :app:extractPythonBuildPackages                                                                                                                  subprocess.py:633
[08:51:41]                                                                                                                                                         subprocess.py:633
           > Task :app:generateDebugPythonRequirements FAILED                                                                                                      subprocess.py:633
           Chaquopy: Installing for arm64-v8a                                                                                                                      subprocess.py:633
           Looking in indexes: https://pypi.org/simple, https://chaquo.com/pypi-7.0, https://chaquo.com/pypi-13.1                                                  subprocess.py:633
           Processing /Users/rkm/beeware/toga/core                                                                                                                 subprocess.py:633
             Installing build dependencies: started                                                                                                                subprocess.py:633
             Installing build dependencies: finished with status 'error'                                                                                           subprocess.py:633
             ERROR: Command errored out with exit status 3:                                                                                                        subprocess.py:633
              command: /Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 '/Users/rkm/beeware/toga/testbed/android/gradle/Toga                      subprocess.py:633
           Testbed/app/build/generated/python/bp/pip' install --ignore-installed --no-user --prefix                                                                                 
           /private/var/folders/b_/khqk71xd45d049kxc_59ltp80000gn/T/pip-build-env-rt3kwp5q/overlay --no-warn-script-location --no-binary :none: --only-binary                       
           :none: -i https://pypi.org/simple --extra-index-url https://chaquo.com/pypi-7.0 --extra-index-url https://chaquo.com/pypi-13.1 -- 'setuptools>=60'                       
                  cwd: None                                                                                                                                        subprocess.py:633
             Complete output (1 lines):                                                                                                                            subprocess.py:633
             ERROR: Could not find an activated virtualenv (required).                                                                                             subprocess.py:633
             ----------------------------------------                                                                                                              subprocess.py:633
           ERROR: Failed to install file:///Users/rkm/beeware/toga/core (from -r requirements.txt (line 1)).                                                       subprocess.py:633
           For assistance, please raise an issue at https://github.com/chaquo/chaquopy/issues.                                                                     subprocess.py:633
           Chaquopy: Exit status 1                                                                                                                                 subprocess.py:633
@mhsmith
Copy link
Member Author

mhsmith commented Jan 25, 2023

@freakboy3742: This was caused by the environment variable PIP_REQUIRE_VIRTUALENV, which I guess you have in your shell startup files. Chaquopy passes pip the --isolated option to make it ignore environment variables, but this doesn't get passed through to the recursive copy of pip that's used to build PEP 517 environments.

In this case you do appear to be in a virtual environment, but my guess is that when you started the Gradle daemon, you were in a different environment with a different version of Python. On macOS at least, subsequent invocations of Gradle don't update the daemon's environment (gradle/gradle#12905 and gradle/gradle#10483). So when you did this build with Python 3.10, it located the python3.10 executable using your original PATH, which is the copy in /Library/Frameworks, not in your virtual env.

The fix is to pass through the --isolated option to the recursive pip process. This is definitely a candidate for submitting to upstream pip.

@freakboy3742
Copy link

Nice catch. Your analysis of my setup is dead on - I have PIP_REQUIRES_VIRTUALENV in my .zshrc, and when I hit this problem, I was moving between projects, so the virtual environment was different. A Python version change between projects is entirely probable, although I can't recall the specifics.

@GPKyte
Copy link

GPKyte commented Nov 14, 2024

Creating a new venv worked for me. While activated, I saw the same activation requirement error. Since recreating worked, I will blame renaming the venv directory after init for pip's failure to detect the venv.

@mhsmith
Copy link
Member Author

mhsmith commented Nov 15, 2024

As the venv documentation says, venvs are "Not considered as movable or copyable" – or renamable.

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

No branches or pull requests

3 participants