I just installed Anaconda on C:\Anaconda3 on the same computer where the old Python was installed on C:\Python34.
There are tools that manage different version of Python or different versions of Anaconda, but I can't find anything that manages different versions of both Python and Anaconda on the same machine at the same time.
I was able to get both the old app to run with Python 3.4 and the new with Anaconda 3.5 using the 4 scripts below. Double clicking on each of them in sequence the two apps run without problems.
But I wasn't able to make one script to run both the apps at once, not even two scripts, one for the first app and one for the second. Any idea how I would solve this problem?
Python1.cmd
setx PATH "[...]C:\Python34[...]"
setx PYTHONPATH "C:\Python34"
setx PYTHONHOME "C:\Python34"
Python2.cmd
cd \OldFolder
C:\Python34\python app.py
Anaconda1.cmd
setx PATH "[...]C:\Anaconda3[...]"
setx PYTHONPATH "C:\Anaconda3"
setx PYTHONHOME "C:\Anaconda3"
Anaconda2.cmd
cd \NewFolder
C:\Python34\python app.py
Using setx works, but only if the script that executes the setx and the one that executes python are not the same (as in the 4 scripts above). Using setx on the same script is ignored by Python or Anaconda.
Using set on the same script where python is executed causes python to crash immediately. Here are the script and the error:
PythonSet.cmd
set PATH="[...]C:\Python34[...]"
set PYTHONPATH="C:\Python34"
set PYTHONHOME="C:\Python34"
cd \OldFolder
C:\Python34\python app.py
Error
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
You are using SETX, which does not change the environment variable. It saves the enviroment variable value in registry, to be used in future processes.
In order to change the value in current process, use SET:
set PATH="[...]C:\Anaconda3[...]"
set PYTHONPATH="C:\Anaconda3"
set PYTHONHOME="C:\Anaconda3"
Related
I have both python 3.11.1 and 3.10.9 installed on my windows 10 system with the appropriate PATH variables configured. I can run python from the command line to access the latest versions interpreter, but python3.10.9, python3.10 and python310 all return with a CommandNotFoundException error. The documentation have led me to believe that using python 3.10.9 would be the correct way to do that, but it seems like this may only apply to unix based systems.
I've tried running C:\Users\user\AppData\Local\Programs\Python\Python310\python as per this thread but that does not work when attempting to pass an argument (e.g. venv) because it treats the second string as path to a file to run with the python executable. C:\Users\operator\AppData\Local\Programs\Python\Python310\python venv app-venv returns:
C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe: can't open file 'D:\app\venv': [Errno 2]
No such file or directory
I am mainly trying to create virtual environments using different python versions, but there may be other reasons I need this in the future.
Quick question regarding the installation of python. I've installed Python 3.7.7 using the Windows 64 bit installer. I also had the installer update the PATH variable for me.
But when doing a quick check with the command-line using the command: "python --version", I'm getting nothing.
Nothing. No error, just an endline.
User Path variable System Path variable command prompt
Edit(1):
By going to the directory with python.exe within the terminal using the command "cd C:\Users\Andrei\AppData\Local\Programs\Python\Python37\" and then using python --version. The command works. I'm receiving the python version 3.7.7 message.
In spite of the path variable pointing to the same folder though, the command still doesn't work when I'm outside it.
A very weird thing I realized is that the command "py" does have some output. Regardless of what directory I'm in.pyOutput
So that command works, while python --version doesn't. In spite of python --version working when I'm within the actual directory of python.exe.
I would assume that while I'm outside the python directory, there's some other executable that the system is accessing first? Regardless, I need all the functionality of python to work as I'm trying to get an external program to work with it and within that program, I'm getting the error that python is not installed. "Download python and add it to the path variable" it still says...
Edit(2)(SOLVED!):
There must've been some other folder within the path that had a python command that was overriding this one, as now it works and all I changed was the position of the folder within the path variable. It previously sat lowest, now it is the first one. And the command always works as intended, regardless of what directory I'm in.previous position new position
First, be sure you added the path to environment variable correctly
for testing, you can open your terminal in your path that you added to the environment variable and run python --version again.
If that not work for you try these solutions:
Close your terminal and open it again
or
try python3 --version instead of python --version
It's probably because you don't have Python installed through the Microsoft Store. You need to write "python" in the cmd and then a Microsoft Store window will pop up and let you download it.
I have successfully installed z3 on a remote server where I am not root. when I try to run my python code I get :
ModuleNotFoundError: No module named 'z3'
I understand that I have to add it to PYTHONPATH in order to work and so I went ahead and done that like this:
export PYTHONPATH=$HOME/usr/lib/python-2.7/site-packages:$PYTHONPATH
I still get the same issue though, how can I verify that it was correctly added to the variables environment? what am i doing wrong?
Did you pass the --python flag when you called scripts/mk_make.py?
See the instructions on https://github.com/Z3Prover/z3/blob/master/README.md on how to exactly enable Python (about all the way down in that page). Here's an example invocation:
python scripts/mk_make.py --prefix=/home/leo --python --pypkgdir=/home/leo/lib/python-2.7/site-packages
Change the directories appropriately, of course.
For Windows users that just downloaded and unzipped the compiled Z3 binary into some arbitrary directory, adding the location of the python directory in the directory where Z3 was installed to PYTHONPATH did the trick. ie in Cygwin : $ export PYTHONPATH=<location of z3>/bin/python:$PYTHONPATH (or the equivalent in a Windows command shell)
I trying to run a program in python 3 that uses numpy but it gives me the error ModuleNotFoundError: No module named 'numpy'. I am using Windows 10. I tried running pip install numpy and it says pip is not a recognized command
You need to add python to your environment variables
Computer -> System Properties (or Win+Break) -> Advanced System Settings
Click the Environment variables button (in the Advanced tab)
Edit PATH and append ;C:\Python27 to the end (if you need substitute your Python version)
Click OK. Note that changes to the PATH are only reflected in command prompts opened after the change took place.
If you are running python 3.6 you will need to add python to your environment path through command prompt
Windows allows environment variables to be configured permanently at both the User level and the System level, or temporarily in a command prompt.
To temporarily set environment variables, open Command Prompt and use the set command:
set PATH=C:\Program Files\Python 3.6;%PATH%
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
These changes will apply to any further commands executed in that console and will be inherited by any applications started from the console.
To change System variables, you need non-restricted access to your machine (i.e. Administrator rights).
If you were to run python -v it should now work
This came directly from the python documents section 3.3.1
Now after you restart you should be able to access python through the command line. If you are running 2.7.9+ or 3.4+ pip will come prepackaged with python. However, if you are running an earlier version of python
Per https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip:
Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt:
python get-pip.py
You possibly need an administrator command prompt to do this. Follow Start a Command Prompt as an Administrator (Microsoft TechNet).
Thanks to How do I install pip on Windows?
Add "way to folder with your python interpreter" and "way to folder with your python interpreter"\Scripts\ to PATH variable. Computer -> Properties -> Extra options -> Environment variables.
I have installed virtualenv 1.10 on a Windows 7 machine with Python 2.7 on it.
I have created a virtual env called TESTENV. It is located in C:\
If I run C:\TESTENV\Scripts\activate and then type python followed by:
import sys
print sys.prefix
it outputs C:\TESTENV, as exprected.
But if I run D:\virtualenv_test.py (which is a script containing the two lines of code I used above) it outputs C:\Python27.
I tried adding a shebang line to the script but that doesn't work on Windows.
Why is the script not running in the context of the virtual environment?
virtualenv doesn't change the default application that starts a file.
When you installed Python, the installation associated .py and .pyw files with appropriate C:\Python27\python.exe and C:\Python27\pythonw.exe applications. So when you run (in your cmd) only D:\virtualenv_test.py, cmd looks into the registry and finds the application that is associated with .py files and then runs the file with that application. In this case that is the previously installed C:\Python27\python.exe.
virtualenv activate only adds that particular virtual environments python interpreter at the start of the PATH environment variable, so when you type python in cmd you will get the appropriate python.exe executed.
So the solution to your problem is to run your script as:
python D:\virtualenv_test.py
After you activated the environment.