With Mamba, pypy cannot find modules installed using pip? - python

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.

Related

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

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

How do I automatically run on an environment with Spyder?

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

How to setup pip for coexisting Python 2.7/3.4?

I am using Anaconda Python 3.4 on a Windows 7 PC now. Recently I am trying to follow the instruction of the book High Performance Python to learn some profiling skills. To this end I need to use pip install to install several tools. Unfortunately, not all of them support Python 3, and I have to install Python 2.7 now.
Before installing Python 2.7, I would like to know how I should handle with such 2.7/3.4 coexisting system? How do I setup pip so that I could use pip install to install packages for different Python versions separately?
You can create a conda environment via:
conda create --name py27 python=2.7
and use this environment for your work with Python 2.7. Activate it with the command activate py27, going back to your root environment is just activate.
In the py27 environment you can install pip and all other packages you need.
pip is generally located at the Python27\Scripts and/or Python34\Scripts folder. If you wish to invoke pip directly in the command line, these folders should be in your PATH environment variable.
Now I would just rename pip.exe in Python34\Scripts into any other name, for example pip_for_3.exe. That way, when I install packages for Python27, I would just use:
pip install <package name>
and packages for Python34:
pip_for_3 install <package name>
Coexisting Python installations are not a problem, you just have to know which version is invoked every time. See this answer for the same idea.

Django, Python 3.4, CentOS 6.4, virtualenv: ImportError: No module named Django

I am running a Linux server with CentOS 6.4. I need to run Django 1.8.2 with Python 3.4. I already have pip and virtualenv installed, and I am currently in a virtual env. I tried to install Django using the pip command but it has installed it in the Python 2.6 site packages, so when I run a python 3 interpreter and type import django I get ImportError: No module named Django. I need to find a way to install Django with Python 3.4. I do not have pip3 and cannot figure out how to install it. All of the help I have found on other sites deals with Ubuntu systems and do not work for me.
EDIT:
which pip outputs ~/MAP_VIO/bin/pip
which python3 outputs /usr/local/bin/python3
which python outputs ~/MAP_VIO/bin/python
MAP_VIO is my virtual env, so it looks like I don't have python 3 in my virtual env? If that's my problem, how do I solve it?
It seems you installed a Python 2 virtual environment. To get a Python 3 environment you need to do
virtualenv -p python3 venv_path
The -p flag tells it which interpreter you want. That should install both pip3 and setuptools into the environment. If you really don't have pip3 (which virtualenv can copy into the environment) and can't install it system wide for some reason, try doing
easy_install pip
inside the virtual environment. That should be able to fetch and install the right pip for the virtual environment you're in.
Please see that you are using the correct, virtualenv'ed, pip command.
You can verify this by running command:
which pip
... and it will tell you the absolute path of pip command (and Python installation) you are using.
Also do the same for python command you are trying to run Django with. If necessary edit your question and add the relevant information about virtualenv, python and pip paths.

Categories

Resources