How do I automatically run on an environment with Spyder? - python

Sorry if I am unclear/this is a lame question, still very new to setting up my computer.
So I installed Python using Anaconda for work, and at work there are specific packages that are used internally. I used Anaconda Prompt to install these packages by creating an environment and installing internally used packages. I then check to see if the package is there.
In the Anaconda Prompt...
conda create --name environment_name python = 3.4
activate environment_name
pip install <internal package> --upgrade
pip list
However, when I try to import a package on Spyder, it does not recognize the package. Is there a way for Spyder to run code on an environment that I specify? I would like the environment to run automatically on any file that I run using Spyder, being able to pull the packages that I installed on Anaconda Prompt

Related

With Mamba, pypy cannot find modules installed using pip?

I'm testing using pypy for speeding up the execution time of a Python script I wrote. To install the dependencies of the script, I used both pip (some modules I need are not available via anaconda) and Mamba.
When I run the script using pypy script.py, I get an error message saying that the modules I installed using pip are not found (example: ImportError: No module named presidio_analyzer). Why does this happen? And do you have suggestions on how to fix this?
I'm running the tests on OSX. I installed Mamba using micromamba.
To make this work you should:
Create a conda environment that contains python and pip.
Activate the conda environment
Run pip install ...
Run pypy script.py
When you run pip install ... using an instance of pip that is part of your conda environment, then the python packages also get installed into the conda environment.
Your conda environment should also be activated when you run pypy script.py so that the python binary within the conda environment is utilized along with the packages you pip installed.

No module named pandas in conda command prompt

I'm trying to run a script made on spyder that runs with no problem.
But when I try to run the same script it says Pandas is not installed.
But I checked on my conda env e seems to be already installed.
Why this happens?
Problem
You are using pip python's default package manager to install a package in python's default location.
But using Anaconda's virtual environment to run python script which requires packages to be installed in it's own directory via conda package maanger.
Solution
Run this command in Conda command pompt:
conda install -c conda-forge pandas

Packages installed in my virtual environment arent found unless I install them using cmd prompt in windows

I am currently working on a python project using Visual Studio Code and Conda. When I try to install a package in the virtual environment it does not work (details and steps below). But if I use my computers command prompt and install that way, it does work in the virtual environment.
My steps are as follows:
I created a virtual environment as so:
conda create -n envname
Activated the environment:
conda activate envname
Tried to install a package (i tried to use conda install but package wasnt found):
pip install packagename
Then write it into my code like so:
import packagename
Which throws me this error:
ModuleNotFoundError: No module named 'packagename'
I did try the solution from this page and tried installing the package this way:
C:\Users\myname\anaconda3\envs\envname\Scripts\pip install packagename
but it returns this:
Requirement already satisfied: packagename in c:\users\name\anaconda3\envs\envname\lib\site-packages
when i type:
conda list
The package I installed is included, as well as pip. However, the package I installed shows the version # in one column, then only "pypi_0 pypi" in the last column. not sure if that means something is wrong or not.
packagename 3.41 pypi_0 pypi
As mentioned, if I type this in my computers command prompt (separate from VSC and my virtual environment):
pip install packagename
My virtual environment will pick it up as being installed.
I feel all mixed up lol, like some path somewhere isnt right but I cant figure out what
Any ideas?
No Need to explicitly activate the venv
Try using following commands.
Step 1: Create virtual env
python -m venv envname
Step 2: Switch to this newly created virtual env
Windows
.\envname\Scripts\activate
Unix
source envname/bin/activate
Step 3: install packages in the virtual env directory
pip install <packagename>

Installed standalone Python 3.7 after Anaconda Python 3.7, how to access old/specific pip?

I'm relatively new to Python. I installed 3.7 as part of Anaconda package, but it wasn't working with PowerBI since it wasn't able to execute a certain batch file that started the conda venv. A workaround I read about was to install a regular Python 3.7 outside of conda and use that interpreter instead.
It successfully installed, and it was added to path, and when I do pip-list in my command prompt I see only the packages for the new pip which makes sense. How do I access the old pip for my conda python where it had all the packages?
Do you mean how do you install packages in your default Python environment outside of Conda? To achieve this you'd just run pip install to install the packages fresh. If you want the list of previously install items you can use pip list.
conda activate myoldenv
pip freeze > requirements.txt
You can then open requirements.txt to see which packages that you want.
However if you want PBI to work well with Python the cleanest way in my opinion is to setup within a new conda env. The point of Conda is to have different envs for different use cases.
conda create --name VisualisationPBI python=3.7
conda activate VisualisationPBI
pip install seaborn #installs seaborn and dependencies including numpy, pandas and mpl
In PBI options set your Python home directory to "Other" then select your conda directory, probably:
C:\Users\YOURNAME.conda\envs\VisualisationPBI
Conda works with PBI, but you need to Pip install the key packages in the library, instead of conda install. As here: https://community.powerbi.com/t5/Desktop/Power-BI-Python-with-Anaconda-missing-dependency/td-p/665102

Trying to install a pip package in Anaconda

I'm trying to follow this tutorial:
https://learn.microsoft.com/en-us/azure/machine-learning/service/tutorial-data-prep
As part of this I'm trying to do a pip install of azureml as it's not available on conda. However doing a pip install will by default install it to my default python install, and not my conda install.
So I tried following the steps here:
https://conda.io/docs/user-guide/tasks/manage-environments.html#using-pip-in-an-environment
However after following these steps I then launch Jupyter notebook after activating myenv, navigate to the notebook, and try and run:
import azureml.dataprep as dprep
But get the error: ModuleNotFoundError: No module named 'azureml'
Also - I cannot tell if myenv is active in the notebook. The kernel simply says python3.
Be careful, when using pip in anaconda, it is possible that you are mixing pip and pip3.
Run which pip3 to be sure you are using the version that correspond to the virtual environment.
If you are using python3 in the environment, then pip will typically be the correct version to use. Do not use pip3 in that case.
This problem has been documented elsewhere on the web. The problem is that Jupyter notebooks itself only launches in the root environment by default. The simplest solution to getting it to launch for your env (e.g. myenv) is to install Jupyter within your env first. So from the Anaconda command prompt:
activate myenv
pip install jupyter
jupyter
Ps. Use source activate myenv for non-windows machines

Categories

Resources