Conda does not set up properly path for JDK for pyjnius - windows

I have installed pyjnius with conda. However, when I try to import pyjnius it fails
> from jnius import autoclass
File
"C:\Users\OEM\Miniconda3\envs\example-env\lib\site-packages\jnius\__init__.py",
line 12, in <module>
from .jnius import * # noqa ImportError: DLL load failed: The specified module could not be found.
Together with pyjnius conda installs also openjdk. Next, pyjnius looks for jvm.dll in one of PATH directories. DLL could be found in
C:\Users\OEM\Miniconda3\pkgs\openjdk-11.0.1-1017\Library\bin\server
but conda does not include it in PATH. It adds another folder in PATH:
C:\Users\OEM\Miniconda3\envs\example2-env\Library\jre\bin\server
while this directory is missing: JRE has not been installed, only JDK. I can, obviously, include first directory in my PATH, however, this would bypass conda virtual environments concept. How can I solve this problem in an elegant way?
Here's environment.yml to reproduce the problem:
name: example-env
channels:
- conda-forge
dependencies:
- python=3.7
- Cython
- pyjnius
Next, I create and activate as follows:
conda env update --file environment.yml
conda activate example-env

Related

Unable to add folders to PYTHONPATH when creating conda environment

I have a script that is making a conda virtual environment where functions need to be imported from folders outside of the repo. I have tried two approaches to add the folders to the path:
Conda develop:
os.system(conda run -n test_env conda develop ' + PACKAGE_PATH)
Results in:
Permission denied [PACKAGE_PATH]
Create conda.pth manually
path = os.path.join(env_path, 'lib')
if not os.path.exists(path):
os.mkdir(path)
path = os.path.join(path, 'site-packages')
if not os.path.exists(path):
os.mkdir(path)
env_path_file = os.path.join(path, 'conda.pth')
with open(env_path_file, 'w+') as f:
write_line(f, PACKAGE_PATH)
The file is created successfully. But, setting the conda interpreter from test_env (in Pycharm) and doing import sys; sys.path does not show [PACKAGE_PATH] and functions cannot be imported from its folders.
Any suggestions?
Thank you.
This is resolved by using conda develop from outside the environment:
conda develop [package_path]
not
conda run -n conda develop [package_path]

how to solve Module not found error? ( installed the module and error persists)

I have installed the module tradingeconomics on cmd and when i try to import the library it throws this error , how to solve it ?
'
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-7-15897cf55e0a> in <module>
1 #Importing required libraries
----> 2 import tradingeconomics as te
3 import pandas as pd
4 import numpy as np
5 from datetime import datetime,date,timedelta
ModuleNotFoundError: No module named 'tradingeconomics'
It is possible that you installed the module in an environment and you are not working in the environment, or you are working in an environment but the module was installed outside of the environment. I use a conda environment, you can set up one by typing this in the terminal
conda create --new myenv
conda activate myenv
set up pip using the following
conda install -n myenv pip
then you can download modules
pip install tradingeconomics
use conda deactivate to exit the environment,
you can learn more about conda here https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment

Creating Anaconda Environment from YML File Choking on Common Packages - os, pip, pandas

Why is anaconda choking on common packages, in creating an envionment from a YML file? Anaconda COMES with these packages pre-installed in root (or so I thought?)
YML file:
---
name: rasterenv
channels:
- conda-forge
dependencies:
- gdal>=2.2.3
- rasterio
- cython
- jupyter
- matplotlib
- numpy
- pyproj
- shapely
- rasterio
- pandas
- geopandas
- os
- matplotlib
- seaborn
- fiona
- OSMnx
- pip:
- pygeotools
- pygeoprocessing
Trying to build file with: conda env create -f path/to/file
If I create an enviornment with JUST uncommon packages like rasterio, it appears to work. BUT, I want an environment with all! What gives here?
Error is:
ResolvePackageNotFound:
- os
If I remove os from the list, the error then becomes:
ResolvePackageNotFound:
- matplotlib
As #sinoroc pointed out in the comments, os is part of Python standard library and should not be listed as a dependency. (When you do define it as a dependency, Python is going to look for a package called os on all available repositories [PyPI or anaconda.org in this case] and won't find it.)
You can see which packages are part of the standard library by checking the docs here: https://docs.python.org/3/library/
(Also there have been a few questions on SO on how to find out if a particular package is part of the std lib, e.g. How to check if a module/library/package is part of the python standard library?) When you create a new environment the packages from the std lib are the only ones which are available by default. Anything else needs to be installed.
Additionally there are two packages in your yaml file that are listed twice (rasterio and matplotlib) which makes me think that you manually created that file. You can generate a conda environment file by activating an environment and running conda env export > environment.yml which will create a file called environment.yml with all required dependencies.

python package can be installed by pip but not conda

I need the sacred package for a new code base I downloaded. It requires sacred.
https://pypi.python.org/pypi/sacred
conda install sacred fails with
PackageNotFoundError: Package missing in current osx-64 channels:
- sacred
The instruction on the package site only explains how to install with pip. What do you do in this case?
That package is not available as a conda package at all. You can search for packages on anaconda.org: https://anaconda.org/search?q=sacred You can see the type of package in the 4th column. Other Python packages may be available as conda packages, for instance, NumPy: https://anaconda.org/search?q=numpy
As you can see, the conda package numpy is available from a number of different channels (the channel is the name before the slash). If you wanted to install a package from a different channel, you can add the option to the install/create command with the -c/--channel option, or you can add the channel to your configuration conda config --add channels channel-name.
If no conda package exists for a Python package, you can either install via pip (if available) or build your own conda package. This isn't usually too difficult to do for pure Python packages, especially if one can use skeleton to build a recipe from a package on PyPI.
It happens some issue to me before. If your system default Python environment is Conda, then you could download those files from https://pypi.python.org/pypi/sacred#downloads
and manually install by
pip install C:/Destop/some-file.whl

Can't import on Windows/Anaconda

Windows 10, Anaconda 2 or 3
c:\leo.repo\leo-editor>c:\apps\Git\bin\git.exe --version
yields:
git version 2.8.2.windows.1
sys.path contains C:\apps\Git, C:\apps\Git\bin and C:\apps\Git\cmd, but I am getting the dreaded GitCommandNotFound exception. What am I doing wrong?
Executing:
from git import Repo
yields:
[snip]
File "c:\Anaconda3\lib\site-packages\git\cmd.py", line 602, in execute
raise GitCommandNotFound(command, err)
git.exc.GitCommandNotFound: Cmd('git') not found due to: FileNotFoundError('[WinError 2] The system cannot find the file specified')
cmdline: git version
Edward
It appears that installs are different on Anaconda.
Per this page the proper installation procedure is:
conda install -c conda-forge gitpython=2.1.1
Installation on Python 2 was straightforward.
Update: I had to add the following to sys.path for Python 3:
C:\Anaconda3\pkgs\gitdb-0.6.4-py35_1\Lib\site-packages
I have no idea why python 2 installs in site-packages as expected, while python 3 installs in the path shown above.
Update2: I also had to update the Windows PATH variable (not just sys.path) to point to the directory containing git.exe.

Resources