1) I installed python3.5 on windows with the installer. I checked set to path.
2) I installed python2.7 on windows with the installer. I checked set to path.
python 3 is found in C:\Users\amand\AppData\Local\Programs\Python\Python35-32
python 2 is found in C:\Python27
3) I open the command prompt
>>> python -m venv tutorial-env
C:\Python27\python.exe: No module named venv
Okay....so how about...
>>>py -3
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>python -m venv tutorial-env
>File "<stdin>", line 1
python -m venv tutorial-env
^
SyntaxError: invalid syntax
Okay. I closed my command prompt and started a new one. The document said to use this...but...
>>>>python3 -m venv tutorial-env
'python3' is not recognized as an internal or external command,
operable program or batch file.
Documentation that I am referring to
https://docs.python.org/3/tutorial/venv.html
to use a specific python you can do:
python3 -m venv tutorial-env #for python 3
python2 -m venv tutorial-env #for python 2
#if you have multple versions of 3 or 2
python2.7 -m venv tutorial-env #for python 2.7
python3.5 -m venv tutorial-env #for python 3.5 or something along the lines
EDIT
If in Windows and the aboves not working:
#In command prompt
py -3 #or -2
>>> import venv
>>> venv.main('tutorial-env')
or
py -3 -m venv tutorial-env
Related
I'm using ubuntu 22.04 and python version installed there is '3.10.4' while sqlite version is '3.37.2'. I need to use python '3.9.5' and sqlite '3.31.1' because the server that my code will live uses that.
Using pyenv fixes the problem for python but the sqlite one didn't. So I resort on building the sqlite from the source and try to link on pyenv install.
Basically this is what I tried to do:
~$ mkdir -p ~/usrapps/src
~$ cd ~/usrapps/src/
~/usrapps/src$ wget https://www.sqlite.org/2020/sqlite-autoconf-3310100.tar.gz
~/usrapps/src$ tar xvvf sqlite-autoconf-3310100.tar.gz
~/usrapps/src$ cd sqlite-autoconf-3310100/
~/usrapps/src/sqlite-autoconf-3310100$ mkdir -p ~/usrapps/sqlite3311
~/usrapps/src/sqlite-autoconf-3310100$ ./configure --prefix=/home/paulo/usrapps/sqlite3311
~/usrapps/src/sqlite-autoconf-3310100$ make
~/usrapps/src/sqlite-autoconf-3310100$ make install
~/usrapps/src/sqlite-autoconf-3310100$ cd ~/
Here's the full terminal ouput
Now for installation of python 3.9.5, I do this different scenarios but first, brew-pyenv-i is aliased to CC="$(brew --prefix gcc)/bin/gcc-12" pyenv install the reason is I encounter a issue where installing python result to "BUILD FAILED: Mising OpenSSL" even though I have openssl install. Doing this fixed my issue, here's the reference.
I uninstall first python(installed by pyenv) before each scenarios.
scenario 1 - log:
~$ LDFLAGS="-L/home/paulo/usrapps/sqlite3311/lib" CPPFLAGS="-I/home/paulo/usrapps/sqlite3311/include" brew-pyenv-i 3.9.5
scenario 2 - log:
~$ PYTHON_CONFIGURE_OPTS="LD_RUN_PATH=/home/paulo/usrapps/sqlite3311/lib LDFLAGS=-L/home/paulo/usrapps/sqlite3311/lib" brew-pyenv-i 3.9.5
scenario 3 - log:
~$ PYTHON_CONFIGURE_OPTS="LD_RUN_PATH=/home/paulo/usrapps/sqlite3311/lib LDFLAGS=-L/home/paulo/usrapps/sqlite3311/lib CPPFLAGS=-I/home/paulo/usrapps/sqlite3311/include" brew-pyenv-i 3.9.5
All attempts are successfully installed the python 3.9.5, but when I try check the sqlite version, its still same, not '3.31.1'
~$ pyenv shell 3.9.5
~$ python
Python 3.9.5 (default, Aug 26 2022, 08:45:14)
[GCC 12.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.37.2'
I would like to avoid using pysqlite3, because that's mean I have to rewrite some of my code and my goal is not really to use multiple versions of sqlite in my app.
I have read this post but I think it is about using python2 or python3 inside virtual environment.
My problem is bit different, I want to different version of python 3 itself inside virtual environment.
I am using Ubuntu 18.04. I have three different versions of python 3 in my system and all of them seem to work.
They can be started by mentioning specific python version.
eg: python3.6, python3.7, python3.8.
But simply typing python3 will load python 3.7 because it is Anaconda's python version.
sankethbk7777#Lenovo-ideapad:/$ which python3
/home/sankethbk7777/anaconda3/bin/python3
However I want to create a virtual environment with python 3.8 as python version inside it.
(I mean inside my virtual env if I type python3 - python3.8 should boot up).
I tried using this command.
sankethbk7777#Lenovo-ideapad:/$ sudo python3.6 -m venv myproject
sankethbk7777#Lenovo-ideapad:/$ source myproject/bin/activate
(myproject) sankethbk7777#Lenovo-ideapad:/$ python3
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Above we can see that it boots python 3.6 when I type python3.
But when I tried the same for python3.8 this error shows up.
sankethbk7777#Lenovo-ideapad:/$ sudo python3.8 -m venv myproject3
Error: Command '['/myproject3/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
However, I have a working python3.8.
sankethbk7777#Lenovo-ideapad:/$ python3.8
Python 3.8.7 (default, Dec 21 2020, 20:10:35)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
sankethbk7777#Lenovo-ideapad:/$ which python3.8
/usr/bin/python3.8
I will provide any further information please help me with this.
Looks like you have Anaconda distribution of Python. I'd simply create a conda virtual environment with the version of Python you need -
conda create -n py38 python=3.8
That should create a conda virtual environment named py38 with Python version 3.8
To activate it,
conda activate py38
And that should give you Python version 3.8
I'm doing a learn python the hardway tutorial, and they are using python2.7
I got it downloaded but unable to switch back from 3.3 to 2.7
I manipulated PATH variable, adding C:\Python27 but this was no use
any other suggestion?
Rename the python interpreter executables to their respective versions. The OS is just executing the first 'python' executable it finds in the path, which is probably the 3.x version. So in command line, you can type python2 or python3 to select the version of interpreter you want.
Another option is.
you can create virtual environment for python 2.7 version.
And Activate the environment.
And use your virtual env for your python 2.7 learning.
username#mypc:~/dev/learn-code$ virtualenv myenv -p /usr/bin/python
Already using interpreter /usr/bin/python
New python executable in /home/username/dev/learn-code/myenv/bin/python
Installing setuptools, pip, wheel...done.
username#mypc:~/dev/learn-code$
username#mypc:~/dev/learn-code$
username#mypc:~/dev/learn-code$ source myenv/bin/activate
(myenv) username#mypc:~/dev/learn-code$
(myenv) username#mypc:~/dev/learn-code$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello"
hello
>>>
Setting up in windows
environment also similar. see this link
This question already has answers here:
Use different Python version with virtualenv
(41 answers)
Closed 6 years ago.
My default python version on my Debian 8.5 machine is 3.4.2. I want to use python 2.7 for only one project. I have tried running all of the following commands in the terminal one by one, :
virtualenv -p python2.7 env_dir
virtualenv -p python2 env_dir
virtualenv --python=python2.7 env_dir
And this is the file.py inside the env_dir:
print "Hello world from inside env_dir"
Obviously however the file.py still gets executed with python3.4.2, because i run:
python file.py
and i get:
File "file.py", line 1
print "Hello world from inside env_dir"
^
SyntaxError: Missing parentheses in call to 'print'
What is the problem, why it fails to run the code in python2.7?
Update
I have also tried:
virtualenv -p /usr/bin/python2.7 env_dir
source env_dir/bin/activate
(env_dir) amir#amir-debian:~/env_dir$ python file.py
File "file.py", line 1
print "Insid virtual env"
^
SyntaxError: Missing parentheses in call to 'print'
Running python -V after activating returns: Python 3.4.2
Update-2
Here is the process how i try to create my virtualenv and the outputs from terminal:
$ virtualenv --python=/usr/bin/python2.7 venv3
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /home/amir/Desktop/venv3/bin/python2.7
Also creating executable in /home/amir/Desktop/venv3/bin/python
Installing setuptools, pip, wheel...done.
$ source venv3/bin/activate
(venv3) amir#amir-debian:~/Desktop$ python -V
Python 3.4.2
(venv3) amir#amir-debian:~/Desktop$ python
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Why is the working version still 3.4.2 and not 2.7 as i gave as OPTION to vertualenv when creating venv3?
Check if you have python2 by doing python -v
if you do have it, you can do python2 file.py
There's also an answer from here
which is
virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>
You can specify the version of python to use by doing
$ virtualenv venv --python=/usr/bin/python2
python3 is my local Anaconda version of python, while python3.4 is the system one. I can import gi module with python3.4 (probably because i installed it with sudo apt-get install python3-gi) but python3 doesn't see it:
$ python3 -c 'import gi'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'gi'
$ python3.4 -c 'import gi'
$ python3 --version
Python 3.5.1 :: Anaconda 4.0.0 (64-bit)
$ python3.4 --version
Python 3.4.3
$ which python3
/home/kossak/anaconda3/bin/python3
$ which python3.4
/usr/bin/python3.4
$
How should i install gi for Anaconda python? Or maybe i can somehow import sysem-wide modules?
My os:
System: Kernel: 3.19.0-32-generic x86_64 (64 bit gcc: 4.8.2) Desktop: Cinnamon 2.8.8 (Gtk 2.24.23) dm: mdm
Distro: Linux Mint 17.3 Rosa
If you're using conda virtualenv for python-3, you can use
$ conda install -c conda-forge pygobject
in your virtualenv
You can read more about this on:
https://anaconda.org/conda-forge/pygobject
This is how you do it: (example for Linux Mint and python3)
First install gi module using your distro package manager. For Linux Mint it would be:
sudo apt-get install python3-gi
Then run your distro python to check where the module is located:
$ /usr/bin/python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> print(gi)
<module 'gi' from '/usr/lib/python3/dist-packages/gi/__init__.py'>
So in my case the module gi was installed to /usr/lib/python3/dist-packages/gi. Assuming you have your anaconda installed in /home/kossak/anaconda3, create a link to gi module in the proper folder:
ln -s /usr/lib/python3/dist-packages/gi /home/kossak/anaconda3/lib/python3.5/site-packages/
If you have conda virtual environment and want gi module to be available there, the path should be a bit different. Assuming the virtual env is called TEST:
ln -s /usr/lib/python3/dist-packages/gi /home/kossak/anaconda3/envs/TEST/lib/python3.5/site-packages/
and it works:
$ python3
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>>
If you want to perform a proper install (without soft linking) inside a Linux anaconda environment. Keep in mind that the errors may vary if you have not installed gcc previously (I assumed it was installed by default when I posted, however not everyone does so). Install it if you don't know very well what you're doing to avoid missunderstandings
Create or open your conda environment.
Attemp to install pygobject (don't worry, it will most likely throw an error):
pip install pygobject
In linux, it will promp the usual installation progress followed by an error:
(...) Please, try executing the following in your system:
sudo apt install libgirepository1.0-dev
Depending on your operation sistem or installed dependencies, the command name or package name may vary. Just follow the instructions and allow the system to install your packets. This step doesn't change anything, is just to give you the precise info of the package you need on your system. If you run this on Windows, it will ask you to install a specific version of Visual Studio. If you are in Windows, download the required Visual Studio from MS website, install it, reboot your computer and go to step 5 (in my case I never needed step 4 in windows, however, I'm not a MS expert.
Close your conda environment
conda deactivate
Next you need to install pygobject from conda-forge repository in your conda environment. You can add the repo to your favourite conda package manager or simply run the following command as root (it is important to be root). I did it outside the project, but you may do it inside:
conda install -c conda-forge pygobject
In my case conda was not in the path. I had is installed in:
/opt/anaconda3/bin/
You can run the following command from your normal user to find out where conda is:
which conda
Open the conda environment
source activate <your env name>
or the corresponding anaconda activate syntax (I never use it so I cant remember precisely)
Repeat the first step and now the installation wont fail:
pip install pygobject
OR if you specifically want to install gi you can run:
pip install pgi
the correct package is "pgi" NOT "gi"
As gi is a dependency of pygobject, everything will get properly installed. You can check it by running
python
>>> import gi
You may find the following usefull for Windows, although you may need to work it out a bit:
GStreammer python bindings on Windows
for me
conda install -c pkgw/label/superseded gtk3
worked