René's URL Explorer Experiment


Title: Setting Virtual Environment while Embedding Python in C# · Issue #1348 · pythonnet/pythonnet · GitHub

Open Graph Title: Setting Virtual Environment while Embedding Python in C# · Issue #1348 · pythonnet/pythonnet

X Title: Setting Virtual Environment while Embedding Python in C# · Issue #1348 · pythonnet/pythonnet

Description: Environment Pythonnet version: Latest as on 7 Jan 2021 cloned from github official repo Python version: 3.7.8 Operating System: Windows 10 .NET Runtime: .Net Core 3.1 Details P.S. - I was able to solve this issue, however since I didn't ...

Open Graph Description: Environment Pythonnet version: Latest as on 7 Jan 2021 cloned from github official repo Python version: 3.7.8 Operating System: Windows 10 .NET Runtime: .Net Core 3.1 Details P.S. - I was able to s...

X Description: Environment Pythonnet version: Latest as on 7 Jan 2021 cloned from github official repo Python version: 3.7.8 Operating System: Windows 10 .NET Runtime: .Net Core 3.1 Details P.S. - I was able to s...

Opengraph URL: https://github.com/pythonnet/pythonnet/issues/1348

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Setting Virtual Environment while Embedding Python in C#","articleBody":"### Environment\r\n\r\n-   Pythonnet version:  Latest as on 7 Jan 2021 cloned from  github official repo\r\n-   Python version: 3.7.8\r\n-   Operating System: Windows 10\r\n-   .NET Runtime: .Net Core 3.1\r\n\r\n### Details\r\n\r\nP.S. - I was able to solve this issue, however since I didn't find any answer responding to this aspect anywhere, thought it might help the community.\r\n\r\n-   I was trying to run some python codes from my dotnet core project by setting up a local python 3.7 virtual environment created using venv. I setup the compile-time constants in project properties accordingly and followed the steps mentioned [here](https://github.com/pythonnet/pythonnet/wiki/Using-Python.NET-with-Virtual-Environments) to use my virtual environment.  I was trying to import numpy which was already installed in the venv, but every time I was getting a missing basic python library error (like codec etc). \r\n- On further inspection I found that the virtual environment directory does not have these \"basic\" python libraries. These libraries are present in the parent python 3.7 directory (the python which was used to create the venv itself). And since the path to the parent library is alerady present in the PythonPath, they are referred from there when you run python in CMD.  \r\n- But as mentioned in your documentation, instead of appending new values to PYTHONPATH, you are changing it completely and pointing it towards just the venv directory which does not have all the python files required.\r\n- I was finally able to run python and import the modules in venv after appending the venv path to original PYTHONPATH, instead of assigning it directly.\r\n- To summarise, the PythonEngine.PythonPath should have the \u003c/path/to/Lib/\u003e, \u003c/path/to/Lib/SitePackages/\u003e of the virtual environment python directory and also of the parent python used to create the virtual env. (Another approach could be to check the paths in ```sys.path``` in the python virtual environment and ensure those values are present here too.)\r\n\r\n\r\n-   What commands did I run to trigger this issue? \r\n\r\n```C#\r\n    string pathToVirtualEnv = /path/to/venv/;\r\n\r\n    Environment.SetEnvironmentVariable(\"PATH\", pathToVirtualEnv, EnvironmentVariableTarget.Process);\r\n    Environment.SetEnvironmentVariable(\"PYTHONHOME\", pathToVirtualEnv, EnvironmentVariableTarget.Process);\r\n    Environment.SetEnvironmentVariable(\"PYTHONPATH\", $\"{pathToVirtualEnv}\\\\Lib\\\\site-packages;{pathToVirtualEnv}\\\\Lib\", EnvironmentVariableTarget.Process);\r\n            \r\n            \r\n    PythonEngine.PythonHome = pathToVirtualEnv;\r\n    PythonEngine.PythonPath = Environment.GetEnvironmentVariable(\"PYTHONPATH\", EnvironmentVariableTarget.Process);\r\n```\r\n\r\n-   One of the errors which I faced\r\n\r\n```python\r\nImportError : No module named '_ctypes'\r\n```\r\n\r\n\r\nThis change to the above code finally worked for me. Note - my initial PYTHONPATH points to python path corresponding the parent python I used to create the virtual environment (i.e. Python 3.7)\r\n\r\n```c#\r\nPythonEngine.PythonPath = PythonEngine.PythonPath + \";\"+Environment.GetEnvironmentVariable(\"PYTHONPATH\", EnvironmentVariableTarget.Process);\r\n```\r\n","author":{"url":"https://github.com/shv07","@type":"Person","name":"shv07"},"datePublished":"2021-01-08T07:32:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/1348/pythonnet/issues/1348"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2586326b-edb4-62d9-5777-cc25b8e5b492
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC308:226908:9E9067:DF1DD1:6970B679
html-safe-nonce4ff37cb035656305dbeabff0abfec65a698ff4748ebd6cdf0122711c770b41ee
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzA4OjIyNjkwODo5RTkwNjc6REYxREQxOjY5NzBCNjc5IiwidmlzaXRvcl9pZCI6IjQyMDMzNTU3NDQxMjk1NjIyMzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacbe1aa60fe4cb87bb3ac17886ef741e1b6fd339e71c579ff725def5c5e5f5d681
hovercard-subject-tagissue:781915425
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/1348/issue_layout
twitter:imagehttps://opengraph.githubassets.com/07b4428a69fc1047b78f97b9297b7975b35d24a17e191b435f1e3579d5e7d588/pythonnet/pythonnet/issues/1348
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/07b4428a69fc1047b78f97b9297b7975b35d24a17e191b435f1e3579d5e7d588/pythonnet/pythonnet/issues/1348
og:image:altEnvironment Pythonnet version: Latest as on 7 Jan 2021 cloned from github official repo Python version: 3.7.8 Operating System: Windows 10 .NET Runtime: .Net Core 3.1 Details P.S. - I was able to s...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameshv07
hostnamegithub.com
expected-hostnamegithub.com
None8e0be80373b724b033cdf8a7b1f78bf5fb6a5d7a2182a9a403aa30894606e390
turbo-cache-controlno-preview
go-importgithub.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git
octolytics-dimension-user_id6050430
octolytics-dimension-user_loginpythonnet
octolytics-dimension-repository_id14748123
octolytics-dimension-repository_nwopythonnet/pythonnet
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id14748123
octolytics-dimension-repository_network_root_nwopythonnet/pythonnet
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release84d9d5bf3b01412ea10f7c2429cbfc735ccce9ce
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues/1348#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonnet%2Fpythonnet%2Fissues%2F1348
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonnet%2Fpythonnet%2Fissues%2F1348
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=pythonnet%2Fpythonnet
Reloadhttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues/1348
Reloadhttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues/1348
Reloadhttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues/1348
pythonnet https://patch-diff.githubusercontent.com/pythonnet
pythonnethttps://patch-diff.githubusercontent.com/pythonnet/pythonnet
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpythonnet%2Fpythonnet
Fork 770 https://patch-diff.githubusercontent.com/login?return_to=%2Fpythonnet%2Fpythonnet
Star 5.4k https://patch-diff.githubusercontent.com/login?return_to=%2Fpythonnet%2Fpythonnet
Code https://patch-diff.githubusercontent.com/pythonnet/pythonnet
Issues 155 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues
Pull requests 18 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/pulls
Discussions https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions
Actions https://patch-diff.githubusercontent.com/pythonnet/pythonnet/actions
Projects 0 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/projects
Wiki https://patch-diff.githubusercontent.com/pythonnet/pythonnet/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/pythonnet/pythonnet/security
Please reload this pagehttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues/1348
Insights https://patch-diff.githubusercontent.com/pythonnet/pythonnet/pulse
Code https://patch-diff.githubusercontent.com/pythonnet/pythonnet
Issues https://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues
Pull requests https://patch-diff.githubusercontent.com/pythonnet/pythonnet/pulls
Discussions https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions
Actions https://patch-diff.githubusercontent.com/pythonnet/pythonnet/actions
Projects https://patch-diff.githubusercontent.com/pythonnet/pythonnet/projects
Wiki https://patch-diff.githubusercontent.com/pythonnet/pythonnet/wiki
Security https://patch-diff.githubusercontent.com/pythonnet/pythonnet/security
Insights https://patch-diff.githubusercontent.com/pythonnet/pythonnet/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/pythonnet/pythonnet/issues/1348
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/pythonnet/pythonnet/issues/1348
Setting Virtual Environment while Embedding Python in C#https://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues/1348#top
https://github.com/shv07
https://github.com/shv07
shv07https://github.com/shv07
on Jan 8, 2021https://github.com/pythonnet/pythonnet/issues/1348#issue-781915425
herehttps://github.com/pythonnet/pythonnet/wiki/Using-Python.NET-with-Virtual-Environments
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.