Different python versions in the same environment of Anaconda - python

this is what the cmd shows:
C:\Users\74713\Documents>activate root
(root) C:\Users\74713\Documents>python
Python 3.6.2 |Anaconda custom (64-bit)| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
this is what my IDE shows:
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 6.1.0 -- An enhanced Interactive Python.
the first one's version is 3.6.2 while the second one is 3.6.3
and because of that, I meet trouble in import torchtext, which works well in the cmd(3.6.2) while fails in my IDE(3.6.3)

Related

activating anaconda python even if it's not on conda environment

literally.
in cmd, I want to execute window's python, not conda's
but it always executes conda's
Like this:
C:\Users\RHS>python
Python 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
What I want to execute is window's python.
Like this:
C:\Users\RHS\AppData\Local\Programs\Python\Python39>python
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
I added PATH of python 3.9 and tried changing position of both.
but always same result

What's the behind magic of python os.path.realpath?

Recently, I tried to install pypoetry on my windows. The python I used was installed from MS store. And I found something strange.
C:\Users\Liu.D.H>where python
C:\Users\Liu.D.H\AppData\Local\Microsoft\WindowsApps\python.exe
C:\Users\Liu.D.H\anaconda3\python.exe
C:\Users\Liu.D.H>C:\Users\Liu.D.H\anaconda3\python.exe
Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.realpath("C:/Users/Liu.D.H/AppData/Roaming/pypoetry")
'C:\\Users\\Liu.D.H\\AppData\\Roaming\\pypoetry'
>>> exit()
C:\Users\Liu.D.H>python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.realpath("C:/Users/Liu.D.H/AppData/Roaming/pypoetry")
'C:\\Users\\Liu.D.H\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\Roaming\\pypoetry'
>>> exit()
C:\Users\Liu.D.H>
I also tried the realpath of node.
C:\Users\Liu.D.H>node
Welcome to Node.js v14.18.1.
Type ".help" for more information.
> fs.realpathSync("C:/Users/Liu.D.H/AppData/Roaming/pypoetry")
Uncaught:
Error: ENOENT: no such file or directory, lstat 'C:\Users\Liu.D.H\AppData\Roaming\pypoetry'
at Object.realpathSync (fs.js:1800:7) {
errno: -4058,
syscall: 'lstat',
code: 'ENOENT',
path: 'C:\\Users\\Liu.D.H\\AppData\\Roaming\\pypoetry'
}
>
So, the %APPDATA%/sub_path location in windows is process-dependent?

Why did the python version not switch after conda switched the environment?

python3.7.12 should be the python version of the hsm environment
(hsm) leelee#ubuntu-PowerEdge-T440:~/tools/hsm-master/predict$ which python
/home/leelee/miniconda3/envs/hsm/bin/python
(hsm) leelee#ubuntu-PowerEdge-T440:~/tools/hsm-master/predict$ /home/leelee/miniconda3/envs/hsm/bin/python
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:21)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
But if I type python directly, it will return a 3.9.5 python version
(hsm) leelee#ubuntu-PowerEdge-T440:~/tools/hsm-master/predict$ python
Python 3.9.5 (default, Jun 4 2021, 12:28:51)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
I guess when I type python, I entered /home/leelee/miniconda3/bin/python
(hsm) leelee#ubuntu-PowerEdge-T440:~/tools/hsm-master/predict$ which -a python
/home/leelee/miniconda3/envs/hsm/bin/python
/home/leelee/miniconda3/bin/python
(hsm) leelee#ubuntu-PowerEdge-T440:~/tools/hsm-master/predict$ /home/leelee/miniconda3/bin/python
Python 3.9.5 (default, Jun 4 2021, 12:28:51)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
Why does this happen and how can I solve it?
Looks like you added Python to the system PATH, which is not recommended when using conda. Simply check your PATH after conda activation and have a look at the sequence of the Python folders.

Running specific python interpreters form command line

When I open CMD (on windows 10) and enter python it initializes python 3.6.0
C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Now I recently also installed 2.7.6 the interpreter. How can I call both version of Python from CMD?
desired outcome
C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> ^Z
C:\>python2.6
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
You can use Python launcher for Windows:
Python 2.7 interptreter:
C:\> py -2.7
Python 3.6 interpreter:
C:\> py -3.6
You also can run a script with a specific interpreter:
C:\> py -2.7 myScript.py
If its windows machine, to open a specific version of python you can use py from the command line.
example:
py2.7 #for version 2.7
and
py3.6 #for version 3.6
if its a Linux machine you can use the following commands in the command line python
python2.7 #opens version 2.7
and
python3.6 #opens version 3.6

If I change the folder, why is the "ModuleNotFouldError" happened?

My environment is Windows10, and I installed python3.6, tensorflow, and anaconda.
There is no error in the installation.
If I run the "command prompt" (not use anaconda), I can success to run tensorflow.
However, if I use anaconda, a problem is coming.
1st: If I run anaconda prompt and import tensorflow by python, no problem.
2nd: If I change the folder and import tensorflow, the error message "ModuleNotFouldError" is coming.
Why I change the path, I cannot import a module?
History is below.
(c:\Users\**Username**\Anaconda3) c:\Users\**Username**\>python
Python 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits", or "license" for more information
>>>import tensorflow
>>>exit()
(c:\Users\**Username**\Anaconda3) c:\Users\**Username**\>cd workspace
(c:\Users\**Username**\Anaconda3) c:\Users\**Username**\workspace>python
Python 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC 1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits", or "license" for more information
>>>import tensorflow
Trackback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'tensorflow'

Categories