Related Articles

Related Articles

How to Import Python Packages in Julia?
  • Last Updated : 01 Nov, 2020

Julia is a high-level, high-performance, dynamic programming language for numerical computing.  Users can import arbitrary Python modules and libraries into Julia. PyCall package is provided for calling Python from Julia code. You can use PyCall from any Julia code, including within Julia modules. And add this package to the Julia environment with Pkg.add (“PyCall”).

PyCall provides many routines for manipulating Python objects in Julia via a type PyObject. In most cases, PyCall automatically makes the appropriate type conversions to Julia types based on runtime inspection of the Python objects.

To Import Python Packages in Julia. Follow the steps below:

Step 1: using Pkg

Step 2: Pkg.add(“PyCall”)



Step 3: using PyCall

Step 4: @pyimport python_library_name 

or

Step 4: pyimport(“python_library_name”)

Example 1:

Julia

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to import math python package
using Pkg
  
# add PyCall package
Pkg.add("PyCall")   
  
# use PyCall
using PyCall        
  
# import python library
@pyimport math      
  
print(math.sin(90))

chevron_right


Example 1

Example 2:

Julia

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to import numpy python library
using Pkg
  
# add PyCall package
Pkg.add("PyCall")      
  
# use PyCall package
using PyCall           
  
# import python library
@pyimport numpy        
  
# or np = pyimport("numpy")
  
# define array using numpy
array1 = numpy.array([1, 2, 3, 4
                      5, 6, 7, 8, 9])   
  
# print array
print(array1) 
print('\n'
  
# print array mean
print(numpy.mean(array1))

chevron_right


Example 2




My Personal Notes arrow_drop_up
Recommended Articles
Page :