Skip to content

Commit c84d7fa

Browse files
committed
Use actual Python path when creating virtual environment
1 parent c5d270d commit c84d7fa

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/installer/stages/platformio-core.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ export default class PlatformIOCoreStage extends BaseStage {
162162
});
163163
}
164164

165-
async createVirtualenvWithLocal(pythonExecutable) {
165+
async createVirtualenvWithLocal() {
166166
let result = undefined;
167167
this.cleanVirtualEnvDir();
168+
const pythonExecutable = await this.whereIsPython();
168169
try {
169170
result = await new Promise((resolve, reject) => {
170171
misc.runCommand(
@@ -198,7 +199,7 @@ export default class PlatformIOCoreStage extends BaseStage {
198199
return result;
199200
}
200201

201-
async createVirtualenvWithDownload(pythonExecutable) {
202+
async createVirtualenvWithDownload() {
202203
this.cleanVirtualEnvDir();
203204
const archivePath = await helpers.download(
204205
PlatformIOCoreStage.virtualenvUrl,
@@ -214,6 +215,7 @@ export default class PlatformIOCoreStage extends BaseStage {
214215
if (!virtualenvScript) {
215216
throw new Error('Can not find virtualenv.py script');
216217
}
218+
const pythonExecutable = await this.whereIsPython();
217219
return new Promise((resolve, reject) => {
218220
misc.runCommand(
219221
pythonExecutable,
@@ -227,7 +229,7 @@ export default class PlatformIOCoreStage extends BaseStage {
227229
if (code === 0) {
228230
return resolve(stdout);
229231
} else {
230-
let userNotification = `Virtualenv Create: ${stderr}`;
232+
let userNotification = `Virtualenv Create: ${stderr}\n${stdout}`;
231233
if (stderr.includes('WindowsError: [Error 5]')) {
232234
userNotification = `If you use Antivirus, it can block PlatformIO Installer. Try to disable it for a while.\n\n${userNotification}`;
233235
}
@@ -238,7 +240,8 @@ export default class PlatformIOCoreStage extends BaseStage {
238240
});
239241
}
240242

241-
installVirtualenvPackage(pythonExecutable) {
243+
async installVirtualenvPackage() {
244+
const pythonExecutable = await this.whereIsPython();
242245
return new Promise((resolve, reject) => {
243246
misc.runCommand(
244247
pythonExecutable,
@@ -258,23 +261,22 @@ export default class PlatformIOCoreStage extends BaseStage {
258261
if (await this.isCondaInstalled()) {
259262
return await this.createVirtualenvWithConda();
260263
}
261-
const pythonExecutable = await this.whereIsPython();
262264
try {
263-
await this.createVirtualenvWithLocal(pythonExecutable);
265+
await this.createVirtualenvWithLocal();
264266
} catch (err) {
265267
console.warn(err);
266268
try {
267-
await this.createVirtualenvWithDownload(pythonExecutable);
269+
await this.createVirtualenvWithDownload();
268270
} catch (err) {
269271
misc.reportError(err);
270272
console.warn(err);
271273
try {
272-
await this.installVirtualenvPackage(pythonExecutable);
273-
await this.createVirtualenvWithLocal(pythonExecutable);
274+
await this.installVirtualenvPackage();
275+
await this.createVirtualenvWithLocal();
274276
} catch (err) {
275277
misc.reportError(err);
276278
console.warn(err);
277-
throw new Error('Could not create PIO Core Virtual Environment. Please create it manually -> http://bit.ly/pio-core-virtualenv');
279+
throw new Error(`Could not create PIO Core Virtual Environment. Please create it manually -> http://bit.ly/pio-core-virtualenv \n ${err.toString()}`);
278280
}
279281
}
280282
}

0 commit comments

Comments
 (0)