# Error with Openpyxl: Pyimport is not in current path

**URL:** <https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460>\
**Category:** Data\
**Tags:** data\
**Created:** [March 28, 2019, 2:11pm UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460 "2019-03-28T14:11:48Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [March 28, 2019, 2:11pm UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/1 "2019-03-28T14:11:48Z")

</div>

I am looking for a package which can read and write an excel file cell by cell. I know openpyxl do the job. Is there any other better package in Julia which does the same job?

Now, I am trying to install it, so I used the following piece of code:

```julia
using Pkg
import Conda
Conda.add("openpyxl")
ENV["PYTHON"]="C:\\Python37-x64\\python.exe"; Pkg.build("PyCall")
@pyimport openpyxl

```

I am getting the following error:

> LoadError: LoadError: UndefVarError: @pyimport not defined  
> in expression starting at C:\Users\Administrator\Desktop\Test Code [Julia]\TESTING\_1.jl:14  
> in expression starting at C:\Users\Administrator\Desktop\Test Code [Julia]\TESTING\_1.jl:14  
> top-level scope

How to get rid of this error?

I am using Julia v1.0.0.

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [March 28, 2019, 6:25pm UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/2 "2019-03-28T18:25:50Z")

</div>

Looks like you didn’t call `using PyCall`? Also, note that:

> `@pyimport foo` is deprecated in favor of `foo = pyimport("foo")`.

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [March 28, 2019, 6:29pm UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/3 "2019-03-28T18:29:22Z")

</div>

Another point: If you want to use Conda.jl to install openpyxl, don’t do `ENV["PYTHON"]="C:\\Python37-x64\\python.exe"; Pkg.build("PyCall")`. Run `ENV["PYTHON"]=""; Pkg.build("PyCall")`.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [March 28, 2019, 11:12pm UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/4 "2019-03-28T23:12:13Z")

</div>

> [@Rajat\_Sanyal](#):
>
> Is there any other better package in Julia which does the same job?

You could look at [GitHub - felipenoris/XLSX.jl: Excel file reader and writer for the Julia language.](https://github.com/felipenoris/XLSX.jl)

---

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [March 29, 2019, 9:30am UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/5 "2019-03-29T09:30:11Z")

</div>

Thanks for your response. I have changed the code as follows:

```julia
import Conda
import Pkg
Conda.add("openpyxl")
ENV["PYTHON"]=""; Pkg.build("PyCall")
using PyCall
pyimport("openpyxl")

```

Still, I am getting the following error:

> LoadError: ArgumentError: Package PyCall not found in current path:  
> -Run `import Pkg; Pkg.add("PyCall")` to install the PyCall package.  
> in expression starting at C:\Users\Administrator\Desktop\Rajat\_Sanyal\Test Code [Julia]\TESTING\_1.jl:14  
> require(::Module, ::Symbol) at loading.jl:823

I have found two Julia folders in my system (added both of them in the environment variables) which are as follows:

1. C:\Users\Administrator\AppData\Local\Julia-1.1.0
2. C:\Users\Administrator\.julia

Any idea how to resolve the issue?

---

<div class="post-metadata">

**Author:** ![YongHee-Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yonghee-kim/32/5965_2.png) [@YongHee-Kim](https://discourse.julialang.org/u/YongHee-Kim)\
**Post date:** [March 29, 2019, 10:47am UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/6 "2019-03-29T10:47:33Z")

</div>

have you tried using [Tutorial · XLSX.jl](https://felipenoris.github.io/XLSX.jl/stable/tutorial/) ?

---

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [March 29, 2019, 10:58am UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/7 "2019-03-29T10:58:29Z")

</div>

I have used the XLSX.jl package for data writing, but have not tried for reading. Actually, I have seen the tutorial, but only few examples are provided. I was not sure how it could be used to read an excel file cell by cell. I will try once again, and let you know about it. Thanks!

---

<div class="post-metadata">

**Author:** ![YongHee-Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yonghee-kim/32/5965_2.png) [@YongHee-Kim](https://discourse.julialang.org/u/YongHee-Kim)\
**Post date:** [March 29, 2019, 11:17am UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/8 "2019-03-29T11:17:50Z")

</div>

Reading by cell examples are here 😄 hope it works for you

> <https://github.com/felipenoris/XLSX.jl/blob/master/test/runtests.jl#L430>

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [March 29, 2019, 9:14pm UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/9 "2019-03-29T21:14:01Z")

</div>

> [@Rajat\_Sanyal](#):
>
> Still, I am getting the following error:
> 
> > LoadError: ArgumentError: Package PyCall not found in current path:  
> > -Run `import Pkg; Pkg.add("PyCall")` to install the PyCall package.

Does it work if you do what the error message suggests?

---

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [April 1, 2019, 7:36am UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/10 "2019-04-01T07:36:46Z")

</div>

> [@Rajat\_Sanyal](#):
>
> I have found two Julia folders in my system (added both of them in the environment variables) which are as follows:
> 
> 1. C:\Users\Administrator\AppData\Local\Julia-1.1.0
> 2. C:\Users\Administrator.julia
> 
> Any idea how to resolve the issue?

I am not able to understand how to add the Pycall to the path.

---

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [April 1, 2019, 11:26am UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/11 "2019-04-01T11:26:38Z")

</div>

Hi, @YongHee-Kim thanks for your input. Let me put my problem properly.

_Let us consider we have an excel sheet which contains cities in a row and population is a column. Now, we don’t know how many cities are there. I am trying to write a program which will take the number of cities as an input from a user/or a cell, then save the data in an array._

Let me try to write a mock code:

```julia
G = 10; # Input 
v = zeros(1,10)
f = XLSX.openxlsx("DATA.xlsx", enable_cache=false)
sheet = f["Sheet1"]
for g in 1:G
     v = sheet[g+1,2]
     println("v=$v")
end

```

Doubt:

1. How to do it correctly?
2. Is there any better way to do it?

---

<div class="post-metadata">

**Author:** ![YongHee-Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yonghee-kim/32/5965_2.png) [@YongHee-Kim](https://discourse.julialang.org/u/YongHee-Kim)\
**Post date:** [April 1, 2019, 2:52pm UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/12 "2019-04-01T14:52:36Z")

</div>

You can access all of your excel data with just numbers  
you don’t need excel address types

```julia
using XLSX

xf = XLSX.readxlsx("data.xlsx")

# All datas in 'Sheet1'
mydata = xf["Sheet1"][:]

# access to range
firstrow = mydata[1, :]
firstcolumn = mydata[:, 1]

# so if you want datas until 10th row
g = 10
columnA = mydata[1:g, 1]
columnB = mydata[1:g, 2]

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 1, 2019, 2:57pm UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/13 "2019-04-01T14:57:25Z")

</div>

> [@Rajat\_Sanyal](#):
>
> I am not able to understand how to add the Pycall to the path.

> Run `import Pkg; Pkg.add("PyCall")` to install the PyCall package.

---

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [April 2, 2019, 8:32am UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/14 "2019-04-02T08:32:22Z")

</div>

> [@YongHee-Kim](#):
>
> using XLSX xf = XLSX.readxlsx(“data.xlsx”) # All datas in ‘Sheet1’ mydata = xf[“Sheet1”][:] # access to range firstrow = mydata[1, :] firstcolumn = mydata[:, 1] # so if you want datas until 10th row g = 10 columnA = mydata[1:g, 1] columnB = mydata[1:g, 2]

Thanks a lot. It did the magic. 🙂

---

<div class="post-metadata">

**Author:** ![Rajat\_Sanyal](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Rajat\_Sanyal](https://discourse.julialang.org/u/Rajat_Sanyal)\
**Post date:** [April 2, 2019, 11:01am UTC](https://discourse.julialang.org/t/error-with-openpyxl-pyimport-is-not-in-current-path/22460/15 "2019-04-02T11:01:27Z")

</div>

Just a small doubt. If we do as follows:

> [@YongHee-Kim](#):
>
> xf = XLSX.readxlsx(“data.xlsx”)  
> #all datas in ‘Sheet1’  
> mydata = xf[“Sheet1”][:]

In this case, it reads the whole file first which may be a cumbersome job. Is it possible to extract the data directly? Go to the sheet and extract the columns/rows using the numbers (not using the excel address).

I guess that will drastically reduce the reading time.
