python console - one instance does not recognise packages - python

I have been working on adding AWS data into Power BI using Python. I have the script that ingests it and it is working. My problem is that Power BI gives me an error. I troubleshoot the error and found something I reckon is the source of it. Just need some help to understand it and fix it.
I have a conda env 'poc' and when I run the Python from Anaconda Navigator everything works. I checked where that Python.exe instance is stored. When I run the Python.exe from that folder it does not work.
Here is the code in the Python console when run from the Anaconda Navigator:
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
import pandas
import os
import sys
os.path.dirname(sys.executable)
'C:\\ProgramData\\Anaconda3\\envs\\poc'
Now I go to the specified directory and run the Python.exe and it gives me the error that the env is not activated and it is.
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [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
I also tested the whole approach by installing winPython and it worked (I got AWS data into Power BI).
My question is, how can I use conda env 'poc' or what I am doing wrong when trying to use Anaconda and my 'poc' env?

That's because you need to activate the conda env in the anaconda cmd, and then run it from there.

Related

Poetry can't find Python 2.7 via Pyenv

With Poetry version: 1.1.13 I get the following error when trying to use Python 2.7.18 via Pyenv...
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
This occurs when 2.7.18 is set up locally (pyenv local 2.7.18) and globally (pyenv global 2.7.18). Running python within the directory in question launches the terminal...
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
But when I install Python 3.9.6 and set it as the local Python version, Poetry works perfectly correctly!
Has anyone seen this before? Am I missing something?
%USERPROFILE%.poetry\bin\poetry.bat was calling Python3 which can't find Python2 installs. When installing Poetry get-poetry.py is called. The _which_python method (line 666) determines if the call in poetry.bat is Python3 or Python by which version of Python it finds during the install.
If you have already installed Poetry simply modify the poetry.bat file to be python. For future installations with Pyenv ensure that a 2.7 Python version is set as global.

Why do I need to activate conda and my venv every time i open cmd? Is this normal? [duplicate]

This question already has answers here:
What is a virtualenv, and why should I use one?
(4 answers)
Closed 2 years ago.
I'm super new to programming, i'm trying to learn how to create a project, make venv, and activate it.
Question 1: do i have to activate the conda env every time i open command prompt?
If i open cmd and type in "python" i get this message:
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [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.
>>>
I type in "conda activate" and everything is cool and good. If i close cmd and open it again, it acts as if I never activated conda and gives me the same message again. Is this normal? Do i have to activate the conda env every time?
Question 2: what's the difference between (base), (env), and (base) (env) and why does the following happen?
I followed a tutorial for making a python project, making an env in command prompt, and activating it with "env\Scripts\activate.bat" and got the (env) output. Then i closed cmd, opened it again, and if i navigate to the path where my example env lives, it doesn't say (env) in front of it.
D:\>cd D:/Favorites/1. Programming/LearnPython/PracticeProject
D:\Favorites\1. Programming\LearnPython\PracticeProject>python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [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.
>>> exit()
D:\Favorites\1. Programming\LearnPython\PracticeProject>env\Scripts\activate.bat
(env) D:\Favorites\1. Programming\LearnPython\PracticeProject>python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [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.
>>> exit()
(env) D:\Favorites\1. Programming\LearnPython\PracticeProject>conda activate
(base) (env) D:\Favorites\1. Programming\LearnPython\PracticeProject>python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
I'm sorry that this is really basic. After trying to research this for 2 days i'm kind of lost. I'm at the level where I'm struggling with step 0 of starting a project. Am I supposed to activate whatever env i need every time I open command prompt? Am i supposed to activate venv every time i want to work on the project even if I don't open cmd? Is the fact that my venv doesn't stay activated a problem? What dies (base) mean?
Environments are an important part of Python, especially if you're working on multiple projects with separate dependencies.
...For example if project_a uses Python 2.7, but project_b uses Python 3.6 you would want two separate environments or you're guaranteed to have dependencies issues and an immense headache.
Question 1: do i have to activate the conda env every time i open command prompt?
No, you do not have to activate conda every time you open CMD. This is simply a matter of choice for the developer. That being said, if you are working on a Windows machine and exclusively using a singular Conda environment, you might find it easier to start the Anaconda Terminal rather than starting CMD and having to activate your environment everytime.
If you are frequently switching between environments, than you'll likely be better off starting and stopping you Conda or Python Environments from CMD...again matter of choice.
Question 2: what's the difference between (base), (env), and (base) (env) and why does the following happen?
What you have here are two different environments. Where I assume that base is a Conda Environment and env is a Python Virtual Environment.
If you wish to know more about more about the difference between the two, the following article may be a good place to start https://www.anaconda.com/understanding-conda-and-pip/

How to check if the installed Anaconda is 32-bit or 64-bit?

A few weeks ago, to dabble in IPython notebooks, I had downloaded and installed Anaconda from http://continuum.io/downloads. There was a problem in the installation (either because it was 32-bit or 64-bit — a detail I can't remember) which I solved but uninstalling my first attempt and installing the other version. Then I went about creating my notebooks with some practice problems.
Currently I can run ipython notebook in the command prompt and the notebooks run perfectly well. But the there's no mention of whether the system is 32-bit or 64-bit in the tree of notebooks (or in the tabs nearby).
I would usually sort such issues using the command prompt. But the commands conda --version and ipython --version just yield the respective version numbers and not the information I am looking for.
My operating system is Win7x64 but that hasn't prevented me from installing 32-bit softwares in past.
conda info has this information. If you need to access it programmatically, use conda info --json.
For CentOS 6.7 and miniconda2:
Type python and enter these commands:
import platform
print platform.architecture()
In my case, it gives:
('32bit', '')
Open a standard python console, and in the header it should tell you
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>
conda --v. It displays the Conda version

Anaconda: "conda update conda" issue

Having difficulties after installing Anaconda 1.9.2 Windows x86-64 on Windows 7 (64-bit).
I already had an install of Python 2.7, so I installed for All Users. I selected "Add Anaconda to my PATH environment variable", but I did not select "Register Anaconda as my default Python 2.7".
Install was successful , but upon attempting to run (as Administrator) "conda update conda" and "conda update ipython" I'm getting the following error:
Traceback (most recent call last):
File "C:\Anaconda\Scripts\conda-script.py", line 2 in
from conda.cli import main
ImportError: No module named conda.cli.
I did a system search and I can't find a single instance of conda.cli on my machine, is there some way the install would've missed this file, or is there something else I should have installed? I've seen this question involving 64-bit Linux Anaconda, but not Windows.
Please check whether you have this folder in your system: C:\Anaconda\Lib\site-packages\conda\cli'.
Also please try to check your python path and attach the logs:
(TEST) C:\anaconda3\Scripts>python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import os
>>> print(os.sys.path)
['', 'C:\\anaconda3\\envs\\TEST\\python36.zip', 'C:\\anaconda3\\envs\\TEST\\DLLs', 'C:\\anaconda3\\envs\\TEST\\lib', 'C:\\anaconda3\\envs\\TEST', 'C:\\anaconda3\\envs\\TEST\\lib\\site-packages']

Installing a Python module in Windows

I'm trying to install a Python module on my Windows computer. I installed the development version of the NetBeans IDE to use as my Python editor, and it seems that they install Jython 2.5 under their own program folder, and force you to use that installation for development.
I've been trying to install the PyWhois module for half an hour now, and I'm getting pretty infuriated with the kludginess of developing Python on Windows with Netbeans.
Does anyone know how to install modules with this setup? Should I destroy my dev environment and use something else that would be less rage-inducing?
Jython is Python for Java - are you sure this is what you want? I have answered this for "normal" Python for Windows, I assume this is what you are after.
To use Python under Windows, you need to install the Windows binary installer, which you can download from the Python download page. Make sure you choose the binary installer.
Next, you will need to install setuptools, which you can get from the python package index (pypi).
Once you have installed both, you have Python available under Windows. You should be able to open a command prompt and type "python" to get the python prompt, it should look like this:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Then, to install PyWhois, open a command prompt and type:
C:\>easy_install pywhois
You'll see output like this:
Searching for pywhois
Reading http://pypi.python.org/simple/pywhois/
Best match: pywhois 0.1
Downloading http://pypi.python.org/packages/source/p/pywhois/pywhois-0.1.tar.gz#
md5=b888dcd990574b7b284d9a9f4b300776
Processing pywhois-0.1.tar.gz
Running pywhois-0.1\setup.py -q bdist_egg --dist-dir c:\docume~1\40843\locals~1\
temp\easy_install-hugnul\pywhois-0.1\egg-dist-tmp-aarhii
Adding pywhois 0.1 to easy-install.pth file
Installing pywhois-script.py script to C:\Python27\Scripts
Installing pywhois.exe script to C:\Python27\Scripts
Installing pywhois.exe.manifest script to C:\Python27\Scripts
Installed c:\python27\lib\site-packages\pywhois-0.1-py2.7.egg
Processing dependencies for pywhois
Finished processing dependencies for pywhois
To confirm it is installed, you should be able to import it from Python:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywhois
>>>
Netbeans 7.0 has removed Python support (see http://wiki.netbeans.org/Python70Roadmap) for more information.
This http://wiki.python.org/moin/IntegratedDevelopmentEnvironments wiki entry lists some other IDEs you can try.

Categories

Resources