question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Installer broken with virtualenv 20.x

See original GitHub issue

I tried installing Lektor on Linux via the installer script at https://www.getlektor.com/install.sh. This resulted in the following error messages:

/usr/bin/python: can't open file './src/virtualenv.py': [Errno 2] No such file or directory
/usr/bin/python: can't open file './virtualenv.py': [Errno 2] No such file or directory

It seems the internal structure of the virtualenv package changed again. If I modify the installer script to force an older version of virtualenv, it works again:

VENV_URL = "https://pypi.org/pypi/virtualenv/16.7.9/json"

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:29 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
xlotlucommented, Mar 17, 2020

Anyone up for making a PR?

I’ll do it.

2reactions
kodmasincommented, Mar 16, 2020

No reason except I am more familiar with wget. Here is curl version:

--- install.sh	2020-03-16 00:31:08.799577500 +0100
+++ /mnt/e/programs/lektor/install.sh	2020-03-16 00:28:00.551836200 +0100
@@ -36,7 +36,7 @@
 
     sys.stdin = open('/dev/tty', 'r')
 
-    VENV_URL = "https://pypi.python.org/pypi/virtualenv/json"
+    VENV_URL = "https://bootstrap.pypa.io/virtualenv.pyz"
     KNOWN_BINS = ['/usr/local/bin', '/opt/local/bin',
                   os.path.join(os.environ['HOME'], '.bin'),
                   os.path.join(os.environ['HOME'], '.local', 'bin')]
@@ -114,17 +114,14 @@
 
     def install(virtualenv_url, lib_dir, bin_dir):
         t = tempfile.mkdtemp()
-        Popen('curl -sf "%s" | tar -xzf - --strip-components=1' %
+        Popen('curl -O "%s"' %
               virtualenv_url, shell=True, cwd=t).wait()
 
         try:
             os.makedirs(lib_dir)
         except OSError:
             pass
-        try:  # virtualenv 16.1.0, 17+
-            check_output([sys.executable, './src/virtualenv.py', lib_dir], cwd=t)
-        except CalledProcessError:  # older virtualenv
-            Popen([sys.executable, './virtualenv.py', lib_dir], cwd=t).wait()
+        Popen([sys.executable, './virtualenv.pyz', lib_dir], cwd=t).wait()
         Popen([os.path.join(lib_dir, 'bin', 'pip'),
            'install', '--upgrade', 'Lektor']).wait()
         os.symlink(os.path.join(lib_dir, 'bin', 'lektor'),
@@ -155,14 +152,7 @@
 
         if prompt: get_confirmation()
 
-        for url in json.loads(urlopen(VENV_URL).read().decode('utf-8'))['urls']:
-            if url['python_version'] == 'source':
-                virtualenv = url['url']
-                break
-        else:
-            fail('Could not find virtualenv')
-
-        install(virtualenv, lib_dir, bin_dir)
+        install(VENV_URL, lib_dir, bin_dir)
 
         print('')
         print('All done!')

Here is simple urlretrieve version also but it does not show download progress (for that it will be more complicated to solve python2/3 comaptibility issues):

--- install.sh	2020-03-15 23:50:37.555242800 +0100
+++ /mnt/e/programs/lektor/install.sh	2020-03-15 23:47:40.352555700 +0100
@@ -26,9 +26,9 @@
     import shutil
     from subprocess import CalledProcessError, check_output, Popen
     try:
-        from urllib.request import urlopen
+        from urllib.request import urlopen, urlretrieve
     except ImportError:
-        from urllib import urlopen
+        from urllib import urlopen, urlretrieve
 
     PY2 = sys.version_info[0] == 2
     if PY2:
@@ -36,7 +36,7 @@
 
     sys.stdin = open('/dev/tty', 'r')
 
-    VENV_URL = "https://pypi.python.org/pypi/virtualenv/json"
+    VENV_URL = "https://bootstrap.pypa.io/virtualenv.pyz"
     KNOWN_BINS = ['/usr/local/bin', '/opt/local/bin',
                   os.path.join(os.environ['HOME'], '.bin'),
                   os.path.join(os.environ['HOME'], '.local', 'bin')]
@@ -113,18 +113,26 @@
         sys.exit(1)
 
     def install(virtualenv_url, lib_dir, bin_dir):
-        t = tempfile.mkdtemp()
-        Popen('curl -sf "%s" | tar -xzf - --strip-components=1' %
-              virtualenv_url, shell=True, cwd=t).wait()
+	print('')
+	print("Fetching virtualenv ...")
+	urlfile = urlretrieve(VENV_URL)
+	print('')
+	print("virtualenv fetched")
+	t, vefile =os.path.split(urlfile[0])
 
         try:
             os.makedirs(lib_dir)
         except OSError:
             pass
-        try:  # virtualenv 16.1.0, 17+
-            check_output([sys.executable, './src/virtualenv.py', lib_dir], cwd=t)
-        except CalledProcessError:  # older virtualenv
-            Popen([sys.executable, './virtualenv.py', lib_dir], cwd=t).wait()
+	print('')
+	print("Creating Lektor virtualenv ...")
+	print('')
+        Popen([sys.executable, vefile, lib_dir], cwd=t).wait()
+	print('')
+	print("virtualenv created")
+	print('')
+	print("installing Lektor ...")
+	print('')
         Popen([os.path.join(lib_dir, 'bin', 'pip'),
            'install', '--upgrade', 'Lektor']).wait()
         os.symlink(os.path.join(lib_dir, 'bin', 'lektor'),
@@ -155,14 +163,7 @@
 
         if prompt: get_confirmation()
 
-        for url in json.loads(urlopen(VENV_URL).read().decode('utf-8'))['urls']:
-            if url['python_version'] == 'source':
-                virtualenv = url['url']
-                break
-        else:
-            fail('Could not find virtualenv')
-
-        install(virtualenv, lib_dir, bin_dir)
+        install(VENV_URL, lib_dir, bin_dir)
 
         print('')
         print('All done!')

I just tested this with python2 so I am not sure is it working with python3

Read more comments on GitHub >

github_iconTop Results From Across the Web

pip install break with 20.0.6 within virtualenv #1669 - GitHub
Issue Installing black from source in a new virtualenv does not work anymore, and throws an error No module named pip Environment Docker ......
Read more >
Pip installation in virtualenv broken - Stack Overflow
Solution is to wipe the pyenv folder, and reinstall a fresh virtualenv (if you've been using a requirements.txt file, this is what the...
Read more >
User Guide — virtualenv 20.17.2.dev2+g6845f6f documentation
Phase 2 creates a virtual environment at the specified destination ( dest ), this can be broken down into four further sub-steps: create...
Read more >
How To Install Virtualenv on Mac OS - YouTube
Quick walkthrough on how to install Virtualenv on Mac OS two different ways. This is an easy way to manage Python and it's...
Read more >
Cannot install python venv on Ubuntu 20.04 after upgrading ...
As your original error mentions, you need to install the python3-venv ... After that is done, you need to create a venv by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found