Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
* Remove Scripts directory

The Scripts directory contains executables that won't work on user system. The user needs to run ensurepip to make recreate the scripts.

* Update README.md

* Check if Scripts directory exists

* Add logging to download.ps1

* Add /fa argument to msiexec command line

Try to force installation even if there is a previous installation

* Uninstall previous 2.x python
  • Loading branch information
oswjk authored Aug 19, 2019
1 parent 82d748d commit 9780b1f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,25 @@ If you answered yes at least once, then this project will have you covered!
This project contains a bunch of Python releases packaged in zip archives. The archives are created from files installed by the official Python installer, nothing else. Each version will have a 32-bit and 64-bit version available.

Check out [releases](https://github.com/oswjk/portablepython/releases) for downloads!

# Recreating scripts

A normal Python installation can be configured to have a Scripts directory that contains `pip` and `easy_install` scripts that you can invoke directly.

The portable zip file does not contain this directory. If you need it, it is easy to recreate with the `ensurepip` package.

First, you need to uninstall pip and setuptools:

```
python -m pip uninstall setuptools pip
```

Now you can run the `ensurepip` package to install `pip` and `setuptools` and to create the scripts:

```
python -m ensurepip --default-pip
```

Make sure that the Python you are invoking, is the correct one! You can do this for example by specifying the full path to the Python executable when entering the commands above.

That should be all!
14 changes: 14 additions & 0 deletions download.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,32 @@ Write-Output "Target: $target"
Write-Output "Target dir: $targetdir"
Write-Output "Log file: $logfile"

Write-Output "Downloading $url"
$client = New-Object System.Net.WebClient
$client.DownloadFile($url, $target)

if ($env:PYVERSION -like "3.*") {
# Replace TARGET_DIR in unattend.xml.in with our target directory
((Get-Content -path unattend.xml.in -raw) -replace 'TARGET_DIR',$targetdir) | Set-Content -path unattend.xml

Write-Output "Installing Python to $targetdir"
Start-Process -FilePath "$target" -ArgumentList "/quiet","/log","$logfile" -Wait

# Remove all __pycache__ directories
Write-Output "Removing __pycache__ directories"
Get-ChildItem -Include __pycache__ -Recurse -Force | Remove-Item -Force -Recurse
} else {
Write-Output "Removing existing Python installation if there is one"
Start-Process -FilePath msiexec -ArgumentList "/qn","/x","$target" -Wait

Write-Output "Installing Python to $targetdir"
Start-Process -FilePath msiexec -ArgumentList "/qn","/i","$target","/L*V","$logfile","TARGETDIR=$targetdir","ADDLOCAL=DefaultFeature,TclTk,Documentation,Tools","REMOVE=Extensions,Testsuite" -Wait

Write-Output "Removing .pyc files"
Get-ChildItem -Include "*.pyc" -Recurse -Force | Remove-Item -Force
}

if (Test-Path $targetdir\Scripts) {
Write-Output "Removing $targetdir\Scripts"
Remove-Item -Recurse -Force $targetdir\Scripts
}

0 comments on commit 9780b1f

Please sign in to comment.